Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nY2pZ-0000SA-JF for pgsql-general@arkaria.postgresql.org; Sat, 26 Mar 2022 09:35:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nY2pX-0003CT-LE for pgsql-general@arkaria.postgresql.org; Sat, 26 Mar 2022 09:35:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nY2pX-0003CI-9N for pgsql-general@lists.postgresql.org; Sat, 26 Mar 2022 09:35:31 +0000 Received: from susanne.redcor.ch ([178.63.103.72]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nY2pU-0002Zl-Cf for pgsql-general@lists.postgresql.org; Sat, 26 Mar 2022 09:35:30 +0000 Received: from [192.168.0.43] (84-72-41-4.dclient.hispeed.ch [84.72.41.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: robert@redo2oo.ch) by susanne.redcor.ch (Postfix) with ESMTPSA id 656BBA01E0; Sat, 26 Mar 2022 10:35:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=redo2oo.ch; s=201908; t=1648287325; bh=JbOSQMjTTHKFhnToVwvXzri37q70yp88rGdefnrlt5Q=; h=Date:To:From:Subject:From; b=kn38vGj+JZxbIeG/oFCDNUsal04uqLHnxi00raPu9Uujm/wSjLxDrDUfleCYdUFSp uQ9TxGMzqhtMh36Pg637o2ousYLC2h7wxtCmVpmAcxqZ5HtvllWOu6giubROY6IobX 0mHe/OmiAa5UrUqhd9SBjhvTQyL5rNY6TDnpI9i2KWj+4B56rxIwt1rewwA/kFWVHP EsKLvrhEV1YlNAtR7B+ZWOkDAzyPhwiqQ2VyZVxBYmDzU7Ptdjq7hvP8rhTKX529LT qkSW/7rPvn4Kjna4+sGZ8WJeNiWErUkUD1kkL/EqQAxNBA42xK3s6gJYsL3XDLQiQG sjgTtbySCT8vg== Content-Type: multipart/alternative; boundary="------------UNGhkV20lAMSks8CCtk6Bmg8" Message-ID: Date: Sat, 26 Mar 2022 10:35:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: pgsql-general@lists.postgresql.org, robert rottermann From: "robert@redo2oo.ch" Subject: dynamically generate path to output file List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------UNGhkV20lAMSks8CCtk6Bmg8 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------UNGhkV20lAMSks8CCtk6Bmg8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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 <= /span>PROCEDURE export_cvs(
varchar
)
AS
$BODY= $
DECLARE
OUTFILE varchar;
=
BEGIN
OUTFILE =3D (home_dir || '/tmp/company.csv');
copy (
= select 'company_'||id = as "External ID",
name as "Name"'True' as "Is a Compa= ny",
email,
phone ,
company_registry
from res_company
) TO OUTFILE with CSV HEADER;
END;
$BODY$
LAN= GUAGE plpgsql;

this produces a syntax error:

psql:export_contacts_short.sql:21: ERROR:=C2=A0 syntax error at or= near "OUTFILE"
LINE 17:=C2=A0=C2=A0=C2=A0=C2=A0 ) TO OUTFILE=C2=A0 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


--------------UNGhkV20lAMSks8CCtk6Bmg8--