From: | Chris <dmagick(at)gmail(dot)com> |
---|---|
To: | jia ding <dingjia(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: \copy combine with SELECT |
Date: | 2006-03-16 23:45:16 |
Message-ID: | 4419F88C.3040907@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
jia ding wrote:
> yes, of couse COPY
>
> but,
> => copy test to 'test.txt';
> ERROR: must be superuser to COPY to or from a file
> HINT: Anyone can COPY to stdout or from stdin. psql's \copy command
> also works for anyone.
Straight from the documentation:
Do not confuse COPY with the psql instruction \copy. \copy invokes COPY
FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in a file
accessible to the psql client. Thus, file accessibility and access
rights depend on the client rather than the server when \copy is used.
http://www.postgresql.org/docs/8.1/static/sql-copy.html
Doesn't look like \copy lets you specify which fields to include though.
alive=# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
a | integer |
db=# \copy a to ./blah.sql (works)
db=# \copy a a to ./blah.sql
\copy: parse error at "a"
> On 3/16/06, *Chris* <dmagick(at)gmail(dot)com <mailto:dmagick(at)gmail(dot)com>> wrote:
>
> jia ding wrote:
> > Hi all,
> >
> > I tried:
> > select id, name into table2 from table1;
> > \copy table2 to filename.txt
> > in order to export 2 columns from table1 to a file.
> >
> > But, I am thinking, if there is a command can combine these two
> command
> > together?
> > Maybe, something like: \copy select id,name from table to
> filename.txt
>
> Close.
>
> copy tablename field1, field2 to 'filename';
>
> http://www.postgresql.org/docs/8.1/static/sql-copy.html
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
--
Postgresql & php tutorials
http://www.designmagick.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2006-03-17 00:05:11 | Re: will slony work for this ? |
Previous Message | Tom Lane | 2006-03-16 23:10:41 | Re: pg_dumpall: permission denied for relation pg_shadow |