How can I pass command line args to sql files ran with psql
(Postgres)?
i.e.
psql mydatabase < mysqlfile.sql arg1 arg2 arg3...
Is this possible?
How can I pass command line args to sql files ran with psql
(Postgres)?
i.e.
psql mydatabase < mysqlfile.sql arg1 arg2 arg3...
Is this possible?
Use variable interpolation feature in psql.
If you specify
-v variable1=value1
or--set variable1=value1
parameter on command line, then:variable1
in the sql file will be replaced with corresponding text value.Note: use standard-SQL quoted strings if you need quotes, spaces and so on.
Example: