Questions tagged [plpgsql]

PL/pgSQL is the default procedural language for PostgreSQL. Questions about PL/pgSQL should probably be tagged [PostgreSQL] as well.

PL/pgSQL is the default procedural language for PostgreSQL. It can be used to write user defined functions and trigger functions. Since PostgreSQL 9.0, PL/pgSQL is installed by default. It can be used in anonymous code blocks using the DO statement, in functions and in procedures (since Postgres 11).

Reference:

414 questions
4
votes
1 answer

Is there an easier way to show why this query is always equivalent to bitor?

This works, and I can't see right off the bat why: CREATE OR REPLACE FUNCTION bitor ( x bigint, y bigint ) RETURNS bigint AS $body$ BEGIN RETURN x + y - bitand(x,y); END; $body$ LANGUAGE PLPGSQL ; I have posted a couple things around SE for a…
galois
  • 141
  • 3
2
votes
2 answers

How to return a single composite type from a plpgsql function without repeating the composite type's parts explicitly as OUT parameters?

I've hunted online and through documentation, but the much more common use case appears to be returning a SETOF some particular row type, not just a single row. The use case below is trivial for illustration, as I am just trying to determine if this…
Wildcard
  • 588
  • 5
  • 16
1
vote
0 answers

PostgreSQL multiple database dml

I want to insert same data in db_two.tab_emp table automatic by trigger or anything. create database db_one; create table db_one.tab_emp(id int, name text); create database db_two; create table db_two.tab_emp(id int, name text); insert into…
Mazib Bhuiyan
  • 401
  • 1
  • 4
  • 16
0
votes
1 answer

Call dynamically a function using plpgsql

I create a function that returns the value of a field when the id is given : CREATE OR REPLACE FUNCTION get_dcteam(id int) RETURNS text AS $$ #print_strict_params on DECLARE dc_team text; BEGIN SELECT monitoring_table.dc_team INTO STRICT…