Relative Content

Tag Archive for postgresqlplpgsql

using parametrized query with variable in postgreSQL via pgAdmin

`DO $$ DECLARE lang TEXT; myvar dictionary_keys_view.it%TYPE; begin lang = ‘it’; SELECT INTO myvar lang FROM dictionary_keys_view WHERE key = ‘ENDED’; raise notice ‘title id: %’, myvar; end; $$;` When i execute this in pgadmin i receive: ” NOTICE: title id: it DO Query returned successfully in 101 msec.” where’s the error? thanks in advance […]

plpgsql does not handle exception

i have a table called stock_holdings which does not have data related to account_id and ticker_cd (actually it is empty):
select qty,total_amount from stock_holdings where account_id=1 and ticker_cd=’XYZ’;
qty | total_amount
—–+————–
(0 rows)
however when i run the following plpgsql code block, exception should handle the situation, however i get following results:
NOTICE: before v_qty: -100
NOTICE: before v_total_amount: -1000
NOTICE: after v_qty:
NOTICE: after v_total_amount:
DO

Unhelpful syntax error at end of input Posgresql

Yes there are hundreds of questions like this one, however, they all have different syntax errors. Postgres’s syntax check is not giving me any hints on this one. The insert statements work fine, syntactically if I replace the ID with a fake constant. My error is in how I’ve added the do $$ declare begin end $$ construct here.