I have a problem with a function containing the copy command.
The command below does exactly what I need it to do:
\COPY person2 TO '/usr/local/pgsql/report.csv' USING DELIMITERS ','
However I need this in a function to call from the front-end code, it creates fine but errors when I call it:
user=# CREATE FUNCTION getreport10() returns int as '
user'# BEGIN
user'# \COPY person2 TO ''/usr/local/pgsql/report.csv'' USING DELIMITERS '','';
user'# return 1;
user'# END;'
user-# LANGUAGE 'plpgsql';
CREATE
user=# select getreport10();
ERROR: You must have Postgres superuser privilege to do a COPY directly to or from a file. Anyone can COPY to stdout
orfrom stdin. Psql's \copy command also works for anyone.
It does work if I give the user superuser privileges but I don't really want to do this!
Any suggestions?
Regards,
Sharon Cowling