Search Postgresql Archives

Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Joshua D. Drake wrote:
On 01/03/07, Andrew Madu < andrewmadu@xxxxxxxxx> wrote:
Hi Dave,
my apologies for contacting you off list but i'm having a spot of bother
with postgreSQL sequence setup in rails. In addition to what is mentioned
below, I have place the following line of code in my

The definition of primary key explicitly states that it can't be null.
You are trying to pass a null to user_id which won't work.

Joshua D. Drkae


In MySQL that is traditionally how you tell the RDBMS to use the auto_increment to generate the value. Postgres correctly doesn't allow that (since you might actually try to set a field to NULL accidentally in which case an error is expected).

The portable (and correct) way to do it is to use the DEFAULT keyword like this:

INSERT INTO some_table (id_field) VALUES (DEFAULT);

I just tested on MySQL 5.0.32 and that syntax works fine.

--

Russ.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux