Re: Auto-increment not really working

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: fixed <onefix(at)waste(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Auto-increment not really working
Date: 2003-07-30 03:14:45
Message-ID: 20030729201128.A9822-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 29 Jul 2003, fixed wrote:

> I am a bit puzzed about Postgres' auto-incrementing.
>
> Supposing I have the following table:
>
> CREATE TABLE foo (
> id serial primary key,
> name varchar(20));
>
> Then, I can do the following:
>
> INSERT INTO foo VALUES ('Test');
> INSERT INTO foo VALUES ('Test 2');

I assume you mean
INSERT INTO foo (name) VALUES ('Test');
because those statements should fail with an error trying
to convert 'Test' and 'Test2' into an integer.

> The id for each name inserted should be 1, 2, 3, and so on.
>
> This works for me on small tables. However, earlier, I tried to insert
> about 9000 records through a Perl script and Postgres kept complaining:
>
> Cannot insert a duplicate key into unique index schedule_pkey

I've only seen this if you're trying to insert values into the serial
column manually like if you leave out the column list or if you've
inserted values in the past and not set the sequence past those values.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message btober 2003-07-30 03:32:12 Re: Does the block of code in a stored procedure execute
Previous Message Dima Tkach 2003-07-30 03:10:23 Re: Does the block of code in a stored procedure execute