postgresql - How invoke PL/pgSQL from command line instead of SQL -


i write pl/sql scripts using oracle , i'm trying first pl/pgsql script postgresql. example, created test.sql file.

declare     v_loc_nbr         integer; begin     v_loc_nbr := 0; end; 

which try execute using command line:

\postgresql\9.3\bin\psql.exe -d postgres -f test.sql 

but syntax errors like:

psql:test.sql:4: error: syntax error @ or near "v_loc_nbr"

i think problem trying execute sql when want run pl/pgsql. should command be?

i don't want explain more because erwin explained well.you need wrap sql inside do, test.sql should write this

do $$ declare     v_loc_nbr integer; begin     v_loc_nbr := 0; end; $$ 

and try execute \postgresql\9.3\bin\psql.exe -d postgres -f test.sql


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -