0

I am trying to backup the functions in database using the method described here How to take backup of functions only in Postgres. But it is showing error << was unexpected at this time.

The code I typed in the command prompt is given below.

psql.exe -U postgres -At dbname > /path/to/output/file.sql <<"__END__"
SELECT pg_get_functiondef(f.oid)
FROM pg_catalog.pg_proc f
INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid)
WHERE n.nspname = 'public';
__END__

Please help.

Community
  • 1
  • 1
Akhilesh
  • 1,243
  • 4
  • 16
  • 49

2 Answers2

0

I'm sure there's a way to do it, but the simplest thing is just supply the sql as one line with the -c option:

psql.exe -U postgres -At dbname -c "SELECT pg_get_functiondef(f.oid) FROM pg_catalog.pg_proc f INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) WHERE n.nspname = 'public'" > /path/to/output/file.sql

This is also more portable and will work with tools that need one line, like cron etc

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

This is a shell problem.

<< is a feature of Unix-like shells, while you seem to be using Windows.

Just save the text of the query into a file and run it with the -f flag.

jjanes
  • 37,812
  • 5
  • 27
  • 34
  • I placed the query in a text file and used psql -U postgres -d databasename -f D:\q uery.sql >D:/file.sql – Akhilesh May 27 '14 at 04:37