Обсуждение: Export SELECT statement as SQL queries in file

Поиск
Список
Период
Сортировка

Export SELECT statement as SQL queries in file

От
"Mario Peshev"
Дата:
Hey there,

I'm interested in getting the content of a SQL query into a file (possibly as an INSERT clause). Is it possible to be done with an SQL statement? Now I think it could be realised as [\copy (statement) to 'file'] construction, but it's psql command. Is there another way?

Thanks in advance,
Mario

Re: Export SELECT statement as SQL queries in file

От
Sean Davis
Дата:
On Friday 04 May 2007 09:45, Mario Peshev wrote:
> Hey there,
>
> I'm interested in getting the content of a SQL query into a file (possibly
> as an INSERT clause). Is it possible to be done with an SQL statement? Now
> I think it could be realised as [\copy (statement) to 'file'] construction,
> but it's psql command. Is there another way?

There is also a server-side copy:

http://www.postgresql.org/docs/current/static/sql-copy.html

Otherwise, you will need to use a client (of which there are many).  Also, at
least perl, python, and java all have readily accessible client modules, so
you can write short scripts to do what you want.

Sean