From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | "Rhys A(dot)D(dot) Stewart" <rhys(dot)stewart(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Combining \i and \copy in psql |
Date: | 2018-05-15 15:35:06 |
Message-ID: | CAKFQuwbRDM1e2+m4MLdYr6wOo1KU8y4CVbbmO5G9A56woFzrHQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, May 15, 2018 at 8:30 AM, Rhys A.D. Stewart <rhys(dot)stewart(at)gmail(dot)com>
wrote:
> Greetings,
>
> I have a query in a .sql file and I'd like to use \i to execute it and
> \copy to save it to a csv file. Is there any way to combine the two?
>
> Something along the lines of:
>
> \copy \i myquery.sql to 'output.csv'
>
Maybe try something like:
\o output.csv
COPY (
\i myquery.sql
) TO stdout;
\o
You'll need to use COPY if you want to mix in \i with a query that would
otherwise operate as a standard select query.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | raf | 2018-05-15 23:26:43 | Re: Control PhoneNumber Via SQL |
Previous Message | Rhys A.D. Stewart | 2018-05-15 15:30:16 | Combining \i and \copy in psql |