Category "plpgsql"

PLPGSQL function returns ERROR: integer out of range even if value is correct

I'm experiencing strange behaviour on two Postgres functions returning a single bigint value. The first one returns the correct value while the second one throw

How to call substring() with variables?

How to call the substring() function with variables for the start & count parameters? Below example code is not working. DO $$ declare v_idx numeric(3)

How to execute SELECT with params in DataGrip / PgAdmin etc..?

I need to execute a complex query for testing purposes with params. How to write a SELECT query which can be executed in DataGrip / PgAdmin with params: EXECUTE

postgresql function to process partitions separately

I have multiple loosely connected tables, all partitioned the same way by the same key: create table owner( user_id uuid primary key, owned_thing int ) partitio

How to use passed schema name dynamically in a function?

I have function called list_customers, taking i_entity_id, i_finyear as input params. The schema name is built from i_finyear, I need to execute the query based

How to use passed schema name dynamically in a function?

I have function called list_customers, taking i_entity_id, i_finyear as input params. The schema name is built from i_finyear, I need to execute the query based

postgresql function with list of arrays as input

I want a postgresql function that will take a list of arrays, and loop through them. I have written a "hello world" type function that takes a single array and

need the dv/dt for the below table

How to get the dv/dt of the below table in psql Concept is linear regression - but to determine the slope is the what I am facing issue with. voltage || time

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