Re: COPY data into a table with a SERIAL column? - Mailing list pgsql-general

From Rob Sargent
Subject Re: COPY data into a table with a SERIAL column?
Date
Msg-id 5440073F.8050601@gmail.com
Whole thread Raw
In response to Re: COPY data into a table with a SERIAL column?  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-general
On 10/16/2014 11:52 AM, David G Johnston wrote:
On Thu, Oct 16, 2014 at 11:44 AM, lup [via PostgreSQL] <[hidden email]> wrote:


I appreciate the vastness of bigserial but I think it starts at 1.  Are negative numbers even allowed?


A DEFAULT sequence starts at one but it is able to generate any biginteger value.​  Regardless, the value generated by the sequence and the allowed values for the target column are distinct - which is why a sequence attached to a normal integer will start throwing "value out of bounds" errors before it runs out of values.

Therefore, by default if one is able to live with disallowing half of the bigint range for auto-generation using the negative half of the range for manual assignment is a quick-and-simple solution to the problem.

David J.



View this message in context: Re: COPY data into a table with a SERIAL column?
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
As proven by part 4 :)
postgres=# insert into t (id, name) values(-777, 'rjs');
INSERT 0 1
postgres=# select * from t;
  id  | name
------+------
    1 | rjs
  777 | rjs
 -777 | rjs
(3 rows)

pgsql-general by date:

Previous
From: David G Johnston
Date:
Subject: Re: COPY data into a table with a SERIAL column?
Next
From: Igor Neyman
Date:
Subject: Re: Misunderstanding deadlocks