Обсуждение: copy command

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

copy command

От
"Duncan Adams (DNS)"
Дата:
hi all

how do you use the copy command
call me dumb, i have RTFM but i don't seem to get it.

an exstract from my dns.txt file.

aeomc04         10.121.4.157
somcmd1         10.121.23.57
aeomc05         10.121.4.162
gsmomc6         10.121.4.154


wire_dev=> copy dns_ip from dns.txt
wire_dev-> ;
ERROR:  parser: parse error at or near "dns"
wire_dev=> copy dns_ip from /database/pgsql/dns.txt
wire_dev-> ;
ERROR:  parser: parse error at or near "/"
wire_dev=>
wire_dev=> \d dns_ip               Table "dns_ip"Attribute |         Type          | Modifier
-----------+-----------------------+----------dns       | character varying(32) |ip        | character varying(32) |

thanx



Re: copy command

От
"ARP"
Дата:
I think you need the quote around the file name since it's not a keyword and it's text.
Then your dns.txt file needs to be formated correctly, especially concerning the separator : by default I think TABs
areused and \N is used to say NULL. You can go aver that with USING DELIMITERS ';' for example and WITH NULL AS '' if
yourdns.txt look like this : 
aeomc04;10.121.4.157
somcmd1;10.121.23.57
aeomc05;10.121.4.162
gsmomc6;10.121.4.154

hope this helps
Arnaud

----- Original Message -----
From: "Duncan Adams (DNS)" <duncan.adams@vcontractor.co.za>
To: "postgres sql list" <pgsql-sql@postgresql.org>
Sent: Thursday, April 25, 2002 4:53 PM
Subject: [SQL] copy command


hi all

how do you use the copy command
call me dumb, i have RTFM but i don't seem to get it.

an exstract from my dns.txt file.

aeomc04         10.121.4.157
somcmd1         10.121.23.57
aeomc05         10.121.4.162
gsmomc6         10.121.4.154


wire_dev=> copy dns_ip from dns.txt
wire_dev-> ;
ERROR:  parser: parse error at or near "dns"
wire_dev=> copy dns_ip from /database/pgsql/dns.txt
wire_dev-> ;
ERROR:  parser: parse error at or near "/"
wire_dev=>
wire_dev=> \d dns_ip               Table "dns_ip"Attribute |         Type          | Modifier
-----------+-----------------------+----------dns       | character varying(32) |ip        | character varying(32) |

thanx


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly




Re: copy command

От
svilen@iname.com
Дата:
Hello!
You only need to put an "\" in front of "copy". It is an internal command. And you don't need ";" at the end

it would be:
bpsimple=# \copy dns_ip from 'dns.txt'
\.
bpsimple=# SELECT * FROM dns_ip;  dns   |      ip     
---------+---------------aeomc04 | 10.121.4.157somcmd1 | 10.121.23.57aeomc05 | 10.121.4.162gsmomc6 | 10.121.4.154
(4 rows)

\.  is the response and tells you that it worked.
I actually tried it with "\copy dns_ip from dns.txt", without the 
quotes and it also worked perfectly.

Svilen Dyakovski

On 25 Apr 02, at 16:53, Duncan Adams  (DNS) wrote:

> 
> wire_dev=> copy dns_ip from dns.txt
> wire_dev-> ;
> ERROR:  parser: parse error at or near "dns"
> wire_dev=> copy dns_ip from /database/pgsql/dns.txt
> wire_dev-> ;
> ERROR:  parser: parse error at or near "/"
> wire_dev=>
> wire_dev=> \d dns_ip
>                 Table "dns_ip"
>  Attribute |         Type          | Modifier
> -----------+-----------------------+----------
>  dns       | character varying(32) |
>  ip        | character varying(32) |
>