How to pass variable to PL/pgSQL code from the command line?
5
votes
1
answer
8416
views
I am running a psql script from the command line with variables something like:
psql ...... -v now_utc=$NOW_UTC
Then I want to use this in my script like:
$$
DECLARE
_now_date timestamp := :now_utc;
BEGIN
-- do something
END
$$
But I got an error like:
> syntax error at or near ':'
The script is fine once I change from
:now_utc
to now()
and it works like a charm.
The question is how I can pass a variable from the command line to PL/pgSQL code?
Asked by Łukasz Woźniczka
(151 rep)
Jun 13, 2019, 05:41 PM
Last activity: Jun 13, 2023, 09:36 PM
Last activity: Jun 13, 2023, 09:36 PM