pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed\copy multiline
5+ messages / 4 participants
[nested] [flat]
* \copy multiline
@ 2012-11-29 03:21 Seb <spluque@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Seb @ 2012-11-29 03:21 UTC (permalink / raw)
To: pgsql-sql
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?
Cheers,
--
Seb
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \copy multiline
@ 2012-11-29 09:33 Guillaume Lelarge <guillaume@lelarge.info>
parent: Seb <spluque@gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Guillaume Lelarge @ 2012-11-29 09:33 UTC (permalink / raw)
To: Seb <spluque@gmail.com>; +Cc: pgsql-sql
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.
--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \copy multiline
@ 2012-11-29 13:10 Rob Sargentg <robjsargent@gmail.com>
parent: Guillaume Lelarge <guillaume@lelarge.info>
1 sibling, 0 replies; 5+ messages in thread
From: Rob Sargentg @ 2012-11-29 13:10 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \copy multiline
@ 2012-11-29 15:31 Sebastian P. Luque <spluque@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Sebastian P. Luque @ 2012-11-29 15:31 UTC (permalink / raw)
To: Ben Morrow <ben@morrow.me.uk>; +Cc: pgsql-sql
On Thu, 29 Nov 2012 08:01:31 +0000,
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth spluque@gmail.com (Seb):
>> 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?
> CREATE TEMPORARY VIEW?
Of course, that's perfect.
Thanks!
--
Seb
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \copy multiline
@ 2012-11-29 15:35 Sebastian P. Luque <spluque@gmail.com>
parent: Guillaume Lelarge <guillaume@lelarge.info>
1 sibling, 0 replies; 5+ messages in thread
From: Sebastian P. Luque @ 2012-11-29 15:35 UTC (permalink / raw)
To: pgsql-sql
On Thu, 29 Nov 2012 10:33:37 +0100,
Guillaume Lelarge <guillaume@lelarge.info> 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.
Thanks. Someone also suggested creating a temporary view, which helps
keep the schema sane and clean.
Cheers,
--
Seb
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2012-11-29 15:35 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-11-29 03:21 \copy multiline Seb <spluque@gmail.com>
2012-11-29 09:33 ` Guillaume Lelarge <guillaume@lelarge.info>
2012-11-29 13:10 ` Rob Sargentg <robjsargent@gmail.com>
2012-11-29 15:35 ` Sebastian P. Luque <spluque@gmail.com>
2012-11-29 15:31 Re: \copy multiline Sebastian P. Luque <spluque@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox