Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1atiKY-0000V9-5S for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Apr 2016 21:09:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1atiKX-0007vv-Kw for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Apr 2016 21:09:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1atVCC-0000XS-V5 for pgsql-bugs@postgresql.org; Fri, 22 Apr 2016 07:08:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1atVC7-0002Cl-MA for pgsql-bugs@postgresql.org; Fri, 22 Apr 2016 07:08:08 +0000 MIME-Version: 1.0 Subject: BUG #14108: \Copy Command does not takes varibales supplied using -v To: pgsql-bugs@postgresql.org From: neeraj.chaurasia@wipro.com Date: Fri, 22 Apr 2016 07:07:05 +0000 Message-ID: <20160422070705.22934.49259@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 14108 Logged by: Neeraj kumar Email address: neeraj.chaurasia@wipro.com PostgreSQL version: Unsupported/Unknown Operating system: linux Description: I have requirement where I need to spool out data from psql table using copy command. As I am a non super-user the system suggested to use \copy instead of copy and remove ; from end to avoid parsing error. But while executing my sql containing \copy command I supply some variable to indicate out put file name and date etc. The issue face is the variables are not getting initialized here . while in case where we used super user and only copy command it worked well and took all variables. Below is the code and run script, please check if it could be resolved. Copy script \COPY (select MES.CIRCLE AS CIRCLE, MES.subscriber_decimal AS MSISDN, MES.SERVICE_CLASS_ID AS SERVICECLASSCD, MES.SERVICE_CLASS_DESC AS SERVICECLASSDESC, TO_CHAR(MES.ACTIVATION_DT,'DD-MON-YYYY') AS ACTIVATIONDT , TO_CHAR(MES.AIRTIME_EXPIRY_DT,'DD-MON-YYYY') AS AIRTIMEEXPIRYDT, TO_CHAR((TO_DATE(:v2,'YYYYMMDD') - MES.AIRTIME_EXPIRY_DT),'DD-MON-YYYY') AS DAYSINGRACE, TO_CHAR(MES.SERVICE_EXPIRY_DT,'DD-MON-YYYY') AS SERVICEEXPIRYDT, TO_CHAR((TO_DATE(:v2,'YYYYMMDD') - MES.SERVICE_EXPIRY_DT),'DD-MON-YYYY') AS DAYSTOSERVICEEXPIRY, MES.ACCOUNT_BALANCE AS BALANCE, TO_CHAR(MEC.LAST_RECHARGE_DT,'DD-MON-YYYY') AS LASTRECHARGEDT FROM mis_prepaid_south.MIS_ERIC_SUBSCRIBER_INFO MES LEFT OUTER JOIN mis_prepaid_south.MIS_ERIC_CALLDT_TB MEC ON MES.subscriber_decimal=MEC.subscriber_decimal WHERE MES.AIRTIME_EXPIRY_DT <= to_date(:v2, 'YYYYMMDD')-1 GROUP BY 1,2,3,4,5,6,7,8,9,10,11) TO STDOUT WITH CSV HEADER Error : psql: warning: extra command-line argument "v1='/mis_purging/data_sth/SCORP_DLY_GRACE_BASE_20160419.csv'" ignored psql:/export/home/mis_ftp/mis/sql/SCORP_DLY_GRACE_BASE_nee.sql:1: ERROR: syntax error at or near ":" LINE 1: ...YYYY' ) AS AIRTIMEEXPIRYDT, TO_CHAR ( ( TO_DATE ( :v2, 'YYYY... ^ psql:/export/home/mis_ftp/mis/sql/SCORP_DLY_GRACE_BASE_nee.sql:1: \copy: ERROR: syntax error at or near ":" LINE 1: ...YYYY' ) AS AIRTIMEEXPIRYDT, TO_CHAR ( ( TO_DATE ( :v2, 'YYYY... ^ Run script : psql -U repsouth -h mdw dwh -f /export/home/mis_ftp/mis/sql/SCORP_DLY_GRACE_BASE_nee.sql -t -v v2=20160421-v v1=\'/mis_purging/data_sth/SCORP_DLY_GRACE_BASE_20160419.csv\' -v v3=20160421 regards, Neeraj Kumar ph: +91-8587039823 mail: neeraj.chaurasia@wipro.com -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs