Re: COPY with default values?

From: Per-Olof Pettersson <pgsql(at)peope(dot)net>
To: Jeff Boes <jboes(at)nexcerpt(dot)com>
Subject: Re: COPY with default values?
Date: 2001-05-28 06:32:06
Message-ID: 3B11F0E6.3040205@peope.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Jeff Boes wrote:

> Let's say I have a table of keywords, with a SERIAL primary key.
>
> CREATE TABLE keywords (
> key_id SERIAL PRIMARY KEY,
> key_text TEXT
> );
>
> Now I would like to initialize this table with a COPY statement, but
> without supplying values for the primary key. In other words, how can I
> use COPY to perform the same function as
>
> INSERT INTO keywords (keyword_text) VALUES ('foo');
> INSERT INTO keywords (keyword_text) VALUES ('bar');
> ...
>
> I have tried
>
> COPY keywords FROM stdin USING DELIMITERS '|';
> |foo
> |bar
> ...
>
> and also
>
> 0|foo
> 0|bar
>
> and even
>
> \N|foo
> \N|bar
>
> I even tried creating a view on keywords that has only keyword_text, and
> copying into THAT--no luck. Then I wrote a rule to replace inserts on the
> view with inserts on the table, but apparently COPY doesn't trigger INSERT
> rules. Grumble...
>
>
>

If you just want a line-number for the records you could always on UN*X
do "nl file > newfile".

Best regards
Per-Olof Pettersson

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2001-05-28 14:48:35 Re: Compilation --with-python fails on Solaris 8
Previous Message Peter Eisentraut 2001-05-27 21:55:35 Re: [HACKERS] Compile Issue, current CVS/UnixWare 7.1.1

Browse pgsql-general by date

  From Date Subject
Next Message Kémeri Lajos 2001-05-28 06:43:17 Stored Procedure
Previous Message Pruner Jan 2001-05-28 06:18:51 RE: Re: Replace MSSQL by PostgreSQL ?