Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te3tg-0007Lj-Cp for pgsql-sql@arkaria.postgresql.org; Thu, 29 Nov 2012 13:11:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Te3tf-0007O4-U4 for pgsql-sql@arkaria.postgresql.org; Thu, 29 Nov 2012 13:11:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te3te-0007Nv-Vq for pgsql-sql@postgresql.org; Thu, 29 Nov 2012 13:11:19 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te3tY-0005h8-OB for pgsql-sql@postgresql.org; Thu, 29 Nov 2012 13:11:18 +0000 Received: by mail-pa0-f46.google.com with SMTP id bh2so7610078pad.19 for ; Thu, 29 Nov 2012 05:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=AbDvtoIz46bs0TR+hDNer2wCmBxWfvygh+UnlETafLc=; b=d+NpdWqFSvdyxCzHVwy5iI3zNk+4ZuRNKObgtyL7FU8RJeoyF9u+dPV2HJ2gUd4dzz ozemp7tI435qYeJUoL8e2e9+RSEZLqQZSba91uBW5keo0AtvFhJjyOwLbsc19P2UuuVK qDaZP0/jBaMatnaMTV0jHKum6/UVIgnzP5h2zSIEU0wzh3pOW1wKmEWaqzDnauhUSf8u tIvdHd0p5a2CYMs7NzUHDcLvzv5/weUcUZ2xfN6xmX0W65UBrgtO/5EkfDsxnvTvy/Cj v4ZnQ2fDz6EL0PMfSaShYiEHHME3B5DLwNRfXc2mKxZ5U8xcnWIC9+TASRpxHYV9dBUD 70hQ== Received: by 10.68.240.233 with SMTP id wd9mr68200332pbc.127.1354194671195; Thu, 29 Nov 2012 05:11:11 -0800 (PST) Received: from [192.168.1.100] (c-67-169-242-41.hsd1.ut.comcast.net. [67.169.242.41]) by mx.google.com with ESMTPS id oi2sm1223122pbb.62.2012.11.29.05.11.09 (version=SSLv3 cipher=OTHER); Thu, 29 Nov 2012 05:11:09 -0800 (PST) Message-ID: <50B75EDB.5030006@gmail.com> Date: Thu, 29 Nov 2012 06:10:51 -0700 From: Rob Sargentg User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: \copy multiline References: <87r4ndnlfn.fsf@kolob.subpolar.dyndns.org> <1354181617.2124.17.camel@localhost.localdomain> In-Reply-To: <1354181617.2124.17.camel@localhost.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 11/29/2012 02:33 AM, Guillaume Lelarge wrote: > On Wed, 2012-11-28 at 21:21 -0600, Seb wrote: >> Hi, >> >> I use \copy to output tables into CSV files: >> >> \copy (SELECT ...) TO 'a.csv' CSV >> >> but for long and complex SELECT statements, it is cumbersome and >> confusing to write everything in a single line, and multiline statements >> don't seem to be accepted. Is there an alternative, or am I missing an >> continuation-character/option/variable that would allow multiline >> statements in this case? >> > A simple way to workaround this issue is to create a view with your > query and use the view in the \copy meta-command of psql. Of course, it > means you need to have the permission to create views in the database. > > Or maybe a function returning a table or set of records. Might be slightly more flexible than the view. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql