From: | "robert(at)redo2oo(dot)ch" <robert(at)redo2oo(dot)ch> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org, robert rottermann <robert(at)redcor(dot)ch> |
Subject: | dynamically generate path to output file |
Date: | 2022-03-26 09:35:23 |
Message-ID: | bd57256b-162c-ac18-ecc0-968ee582b744@redo2oo.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi Friends
I would like to generate the path of a CSV file to which I output a query.
This is what I try:
CREATEORREPLACEPROCEDUREexport_cvs(
home_dir varchar
)
AS
$BODY$
DECLARE
OUTFILE varchar;
BEGIN
OUTFILE = (home_dir || '/tmp/company.csv');
copy(
select'company_'||id as"External ID",
nameas"Name",'True'as"Is a Company",
email,
phone ,
company_registry
fromres_company
) TOOUTFILE withCSV HEADER;
END;
$BODY$
LANGUAGEplpgsql;
this produces a syntax error:
psql:export_contacts_short.sql:21: ERROR: syntax error at or near "OUTFILE"
LINE 17: ) TO OUTFILE with CSV HEADER;
It works fine when I replace "TO OUTFILE" with a hard coded string.
Can anybody of you give me a hint how to do that?
Thanks a lot.
Robert
From | Date | Subject | |
---|---|---|---|
Next Message | Shaozhong SHI | 2022-03-26 12:12:05 | In what situation, a line feature could not be visible in PgAdmin? |
Previous Message | Laurenz Albe | 2022-03-26 05:08:40 | Re: Leading comments and client applications |