On 02/03/2010 06:59 PM, Yan Cheng Cheok wrote:
> PQexec(Database::instance().getConnection(), "copy unit_1 from
> stdin"); // | serial | int | int /* But I just do not want to put
> 9999 as serial. I want it to be auto-increment. However, I have no
> idea how to make serial auto-increment, without using INSERT. */
> PQputline(Database::instance().getConnection(),"9999\t1\t888\n");
> PQputline(Database::instance().getConnection(),"\\.\n");
> PQendcopy(Database::instance().getConnection());
You really need to get up close and personal with the fine manual.
See:
-----------
http://developer.postgresql.org/pgdocs/postgres/sql-copy.html
Specifically:
-----------
Synopsis
COPY table_name [ ( column [, ...] ) ]
FROM { 'filename' | STDIN }
[ [ WITH ] ( option [, ...] ) ]
Example:
-----------
regression=# create table foo(f1 serial, f2 text);
NOTICE: CREATE TABLE will create implicit sequence "foo_f1_seq" for
serial column "foo.f1"
CREATE TABLE
regression=# copy foo (f2) from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> hello
>> world
>> \.
regression=# select * from foo;
f1 | f2
----+-------
1 | hello
2 | world
(2 rows)
HTH,
Joe