I have the following problem:
I have super simple SQL code from a tutorial, saved into a file test.sql
.
CREATE OR REPLACE FUNCTION add(integer, integer) RETURNS integer
LANGUAGE SQL
AS 'select $1 + $2;'
RETURNS NULL ON NULL INPUT
COST 100;
This code works fine when I am pasting it into the psql
console manually,
starting psql
as:
PGPASSWORD=... psql -v ON_ERROR_STOP=1 -U postgres -S postgres
However, when passing this file as input to the command via a redirection fails:
PGPASSWORD=... psql -v ON_ERROR_STOP=1 -U postgres -S postgres < test.sql
psql:test.sql:1: ERROR: no language specified
This also fails:
PGPASSWORD=... psql -v ON_ERROR_STOP=1 -U postgres -S postgres -f test.sql
psql:test.sql:1: ERROR: no language specified
What is going on?
2