Обсуждение: customising serial type

Поиск
Список
Период
Сортировка

customising serial type

От
Kenneth Gonsalves
Дата:
hi,
in a table with a serial datatype, how do i get the sequence to start
at a specific number like 100000?
--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Re: customising serial type

От
Krasimir Dimitrov
Дата:
On Tuesday 21 June 2005 13:01, you wrote:
> hi,
> in a table with a serial datatype, how do i get the sequence to start 
> at a specific number like 100000?

ALTER SEQUENCE sequence_name RESTART WITH 100000;

-- 
________________________________________________________
Krasimir Dimitrov
IT Department
AII Data Processing Ltd.,
16 Ivan Vazov Str,
Sofia 1000,
Bulgaria
Phone: +359 2 9376 352
E-mail: kr@aiidatapro.com
http://www.see-news.com


Re: customising serial type

От
Michael Glaesemann
Дата:
On Jun 21, 2005, at 7:01 PM, Kenneth Gonsalves wrote:

> in a table with a serial datatype, how do i get the sequence to start
> at a specific number like 100000?

The SERIAL datatype (e.g., CREATE TABLE foo(foo_id SERIAL) )is a  
shorthand for something like
CREATE SEQUENCE foo_id_seq;
CREATE TABLE foo (foo_id integer default nextval('foo_id_seq') );

If you want it to specify the start value, you'll need to either use  
CREATE SEQUENCE first and then create the table with the appropriate  
default, or use ALTER SEQUENCE after creating the table.

http://www.postgresql.org/docs/8.0/interactive/sql-createsequence.html
http://www.postgresql.org/docs/8.0/interactive/sql-altersequence.html

Michael Glaesemann
grzm myrealbox com


Re: customising serial type

От
Stefan Becker
Дата:
Am Dienstag, 21. Juni 2005 12:01 schrieben Sie:
> hi,in a table with a serial datatype, how do i get the sequence to start at
> a specific number like 100000?


Use START in the create sequence statement.
#

create sequence seq_xeingang increment 1 start 1000;
;

CREATE TABLE xeingang  
(  id            integer default nextval('seq_xeingang'), buch        char not null,  eingdt      date not null, jnr
      integer not null, grp           integer, code          integer not null
 
);



my best regards..

Stefan