dynamically generate path to output file - Mailing list pgsql-general

From robert@redo2oo.ch
Subject dynamically generate path to output file
Date
Msg-id bd57256b-162c-ac18-ecc0-968ee582b744@redo2oo.ch
Whole thread Raw
Responses Re: dynamically generate path to output file
List 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:

CREATE OR REPLACE PROCEDURE export_cvs(
home_dir varchar
)
AS
$BODY$
DECLARE
OUTFILE varchar;
BEGIN
OUTFILE = (home_dir || '/tmp/company.csv');
copy (
select 'company_'||id as "External ID",
name as "Name",'True' as "Is a Company",
email,
phone ,
company_registry
from res_company
) TO OUTFILE with CSV HEADER;
END;
$BODY$
LANGUAGE plpgsql;

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


pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Leading comments and client applications
Next
From: Shaozhong SHI
Date:
Subject: In what situation, a line feature could not be visible in PgAdmin?