Re: COPY command details

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY command details
Date: 2007-03-29 15:17:25
Message-ID: 22179.1175181445@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> writes:
> am Thu, dem 29.03.2007, um 0:13:09 -0700 mailte Benjamin Arai folgendes:
>> If I have a PostgreSQL table with records and logical indexes already
>> created, if I use COPY to load additional data, does the COPY update
>> the indexes during, after, or not at all?

> after, i think.

> test=# create table foo (id int primary key, name text);
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
> CREATE TABLE
> test=*# copy foo from stdin;
> Enter data to be copied followed by a newline.
> End with a backslash and a period on a line by itself.
> 1 a
> 2 b
> 2 c
> \.
> ERROR: duplicate key violates unique constraint "foo_pkey"
> CONTEXT: COPY foo, line 3: "2 c"
> test=*#

> I can type the wrong key and the error occurs later with the finaly \.

No, "during" is the right answer. The above only demonstrates that
libpq buffers COPY data in larger-than-one-line units --- once the
data gets to the backend it's inserted and checked a row at a time.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike Charnoky 2007-03-29 15:44:32 Re: disable/enable trigger hangs
Previous Message Tom Lane 2007-03-29 15:14:57 Re: Timestamp precision