Re: going crazy with serial type - Mailing list pgsql-general

From Cindy
Subject Re: going crazy with serial type
Date
Msg-id 6963.1012507861@attalus.tlg.uci.edu
Whole thread Raw
In response to Re: going crazy with serial type  ("Gregory Wood" <gregw@com-stock.com>)
List pgsql-general
"Gregory Wood" writes:
 >> 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.
 >
 >Actually, it has it's own section in the manual:

Of course, making a statement like I did is about the fastest way to
find out what you missed :).  However:

 >http://www.us.postgresql.org/users-lounge/docs/7.1/user/datatype.html#DATATY
 >PE-SERIAL

Yes, but this does not give an example of how to use it.  Ie, what
I need to do to insert properly.  I found this, but it was not helpful,
other than to know I could (in theory) use SERIAL rather than AUTO_INCREMENT.

 >As well as a two questions in the FAQ:
 >
 >http://www.us.postgresql.org/docs/faq-english.html#4.15.1
 >http://www.us.postgresql.org/docs/faq-english.html#4.15.2

OK.  These are helpful, but didn't answer my question of how to make
the insert call unless you're trying to tell me I should call next val
in order to get the value to assign into the record myself.  That
seems to me a very backwards, two step, way to do it, and it doesn't
suprise me I didn't manage to find this.

 >And even more information in the online book:
 >
 >http://www.ca.postgresql.org/docs/aw_pgsql_book/node75.html
 >http://www.ca.postgresql.org/docs/aw_pgsql_book/node76.html

Aha.  Yes, that would have helped.  I never did stumble on the
www.ca.postgresql.org site, though.  Thanks for the reference.

 >Just a guess here, but it seems that '' is being cast into an integer
 >as a 0,

Looks like it.

 >What you want to do is either leave out the serial field:
...
 >Or explicitly give the serial a NULL value:

I'll try the null value!  I have rather more than two fields in
my actual table, of course, which would make listing them tedious.

Thanks!
--
Cindy
ctmoore@uci.edu

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: going crazy with serial type
Next
From: Stephan Szabo
Date:
Subject: Re: Drop Foreign Key