Re: INSERT with SELECT not working in pgAdmin

From: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>
To: Stefan Wild <wilds81(at)yahoo(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT with SELECT not working in pgAdmin
Date: 2010-09-21 18:53:17
Message-ID: AANLkTimwT4uie_kqCxQsODY=TCPv+d0+wzd2wtCQeasZ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey Stefan,

For surrogate keys there is no reason to calculate values manually.
You should use sequences instead. Please, see
http://www.postgresql.org/docs/8.3/static/sql-createsequence.html
You may also use a SERIAL data type which creates a sequence
for you automatically upon its creation. Please, see
http://www.postgresql.org/docs/8.3/static/datatype-numeric.html#DATATYPE-SERIAL
Since you execute INSERT command without specifying an "id" column,
and there is no default value for it, then the default is NULL. So, you need
to define a default and the best solution to define it as next value of
sequence.

--
Regards,
Dmitriy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rhys A.D. Stewart 2010-09-21 19:56:10 versioned pl/pgsql functions
Previous Message Stefan Wild 2010-09-21 18:50:35 Re: INSERT with SELECT not working in pgAdmin