Re: going crazy with serial type

From: Brian Avis <brian(dot)avis(at)searhc(dot)org>
To: Cindy <ctmoore(at)uci(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: going crazy with serial type
Date: 2002-01-31 20:03:13
Message-ID: 3C59A301.7030209@searhc.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I don't believe you have to enter the serial at all.

So instead of this.

insert into mytable ('', 1, 2);

Try this.

insert into mytable (a, b) VALUES (1, 2);

I think that will work the way you want. Although I am a beginner myself.

Good luck.

Cindy wrote:

>OK. My background is in mysql, and I've been converting over to psql. Just
>by way of background.
>
>I do !NOT! understand how the SERIAL type works. I want something
>like I had in mysql that would generate new, unique numbers, each time
>I added a new record. I want something that sits down, shuts up, and
>just GIVES me the number on demand. (I also want a guarantee that the
>unique number is consecutive, and is never zero or negative.) In short,
>I want the AUTO_INCREMENT behavior.
>
>But so far it's been one giant headache. Tell me, how do I insert
>new records into a table *without* specifying an actual number? In
>mysql it's just an empty field. I have been unable to determine how
>to do this in psql other than to ascertain it certainly isn't through
>the same way.
>
>I've been through the documentation, but for some reason, no one seems
>to think a programmer would ever want functionality like mysql's
>AUTO_INCREMENT, so as far as I can tell, it's not even addressed.
>
>I'd appreciate any help. I basically have a table:
>
>create table mytable (mytable_id serial, a int, b int);
>
>and
>
>insert into mytable ('', 1, 2); is accepted but then following
>insert into mytable ('', 5, 6); etc, is rejected due to "duplicate key"
>
>
>Thanks,
>--Cindy
>

--
Brian Avis
SEARHC Medical Clinic
Juneau, AK 99801
(907) 463-4049
cd /pub
more beer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-01-31 20:05:10 Re: going crazy with serial type
Previous Message Stephan Szabo 2002-01-31 20:00:51 Re: Drop Foreign Key