Category "plpgsql"

PostgreSQL duplicate key value violates unique constraint while using on conflict do nothing on insert

Table def: CREATE SEQUENCE IF NOT EXISTS lazy_product_stock_id_seq; CREATE TABLE "public"."lazy_product_stock" ( "id" int4 NOT NULL DEFAULT nextval('lazy_pr

How to force COMMIT inside function so other sessions can see updated row?

In a Postgres 12 database, I have multiple queries (SELECT, UPDATE, ...) in a function that all together take about 20 minutes to complete. I have a check at th

Why doesn't Copy or \copy work for me in Pgsql?

I am trying to import data from a csv into postgres. I have tried the following and got the following errors: Copy TA_Files FROM 'C:\Users\ABla47\Documents\TA

Generate JSON object from a dynamic set of input functions

I am trying to write a function (f_all) that basically just calls other "partial" functions (e.g. f_1,f_2,f_3) and merges the results of them into one final JSO

why does postgres set_config's is_local = true not persist the variable for the whole transaction?

I have a function that uses set_config with is_local = true to set a variable. Now I expected that a select statement using the variable with current_settings w

INSERT INTO temp table not working in stored procedure [duplicate]

This script works fine when running on dbeaver, I can work with the new created temp table: SELECT someField INTO TEMP tmp_TableZZ FROM "_fdw

Syntax error at end of input with IF ... ELSE statement

I'm running this code: CREATE OR REPLACE FUNCTION trg_orders_check() RETURNS trigger LANGUAGE plpgsql AS $func$ BEGIN IF NEW.type = 'prescription' AND NEW

Declare variable set = select

How do I declare a variable for used in a PostgreSQL 9.3 query? CREATE or replace FUNCTION public.test() returns int4 AS $BODY$ DECLARE cod_process bi

Postgresql - SQL query to list all sequences in database

I would like to select all sequences in the database, get the schema of sequence, dependent table, the schema of a table, dependent column. I've tried the follo

PL/pgSQL checking if a row exists

I'm writing a function in PL/pgSQL, and I'm looking for the simplest way to check if a row exists. Right now I'm SELECTing an integer into a boolean, which does

PL/pgSQL SELECT into an array

Here's my function declaration and part of the body: CREATE OR REPLACE FUNCTION access_update() RETURNS void AS $$ DECLARE team_ids bigint[]; BEGIN SELECT

Similar UTF-8 strings for autocomplete field

Background Users can type in a name and the system should match the text, even if the either the user input or the database field contains accented (UTF-8) cha

Filter jsonb results in subselect

I'm building a hierarchical JSON result from several tables. These are just examples but should be sufficient for the purpose of this demonstration to get the i