pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Serial field starting at 100 ?
3+ messages / 2 participants
[nested] [flat]

* Serial field starting at 100 ?
@ 2000-01-07 02:35  Richard Walker <solar92@hotmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Richard Walker @ 2000-01-07 02:35 UTC (permalink / raw)
  To: pgsql-sql

Hello,

In SQLServer, you can do this:

CREATE TABLE fish (
    fishID INTEGER IDENTITY (100, 1) NOT NULL,
    fishName VARCHAR(32) NOT NULL
);

When inserting into that table, you don't mention the first field
and it will automatically use add 1 to the last value in that field,
starting with 100 for the first record.
If you wanted it to start at 25 and increment by 5, you'd put
fishID INTEGER IDENTITY (25, 5) NOT NULL.

I'd like to do something similar to this in PostgreSQL, but the
closest I can get requires that I mention the implicit sequence which
seems unneccessary hassle:

CREATE TABLE fish (
    fishID INT4 SERIAL
    fishName VARCHAR(32) NOT NULL
);

SELECT setval('fish_fishID_seq',99);

(Incrementing by 1 is fine by me).
Is there any way I can do something like:
fishID INT4 SERIAL (100, 1)
or
fishID INT4 SERIAL (START 100)   ?

- Rick


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] Serial field starting at 100 ?
@ 2000-01-07 15:56  Vladimir Terziev <vlady@school.digsys.bg>
  parent: Richard Walker <solar92@hotmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Vladimir Terziev @ 2000-01-07 15:56 UTC (permalink / raw)
  To: Richard Walker <solar92@hotmail.com>; +Cc: pgsql-sql


       Hi Richard,

       You can do the next:


create sequence fish_seq start 100;

create table fish(
    fishID int default nextval('fDish_seq') not null,
    fishName varchar(32) not null
);

The action of the above is what you want!

    Vladimir




On Fri, 7 Jan 2000, Richard Walker wrote:

> Hello,
> 
> In SQLServer, you can do this:
> 
> CREATE TABLE fish (
>     fishID INTEGER IDENTITY (100, 1) NOT NULL,
>     fishName VARCHAR(32) NOT NULL
> );
> 
> When inserting into that table, you don't mention the first field
> and it will automatically use add 1 to the last value in that field,
> starting with 100 for the first record.
> If you wanted it to start at 25 and increment by 5, you'd put
> fishID INTEGER IDENTITY (25, 5) NOT NULL.
> 
> I'd like to do something similar to this in PostgreSQL, but the
> closest I can get requires that I mention the implicit sequence which
> seems unneccessary hassle:
> 
> CREATE TABLE fish (
>     fishID INT4 SERIAL
>     fishName VARCHAR(32) NOT NULL
> );
> 
> SELECT setval('fish_fishID_seq',99);
> 
> (Incrementing by 1 is fine by me).
> Is there any way I can do something like:
> fishID INT4 SERIAL (100, 1)
> or
> fishID INT4 SERIAL (START 100)   ?
> 
> - Rick
> 
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> 
> ************
> 
> 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] Serial field starting at 100 ?
@ 2000-01-09 23:02  Richard Walker <solar92@hotmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Walker @ 2000-01-09 23:02 UTC (permalink / raw)
  To: vlady@school.digsys.bg; +Cc: pgsql-sql

Thanks for your reply,
however the syntax

>create sequence fish_seq start 100;
>
>create table fish(
>     fishID int default nextval('fDish_seq') not null,
>     fishName varchar(32) not null
>);

is exactly the same as this code that I'm currently using
in Postgres:

> > CREATE TABLE fish (
> >     fishID INT4 SERIAL
> >     fishName VARCHAR(32) NOT NULL
> > );
> >
> > SELECT setval('fish_fishID_seq',99);

except that the two sections are switched.
I would have thought that it would have been possible to set the
start value within the "CREATE TABLE" so I don't have to stuff
around in some separate clause using a sequence name that will
never be explicitly used anywhere else in the code.

Perhaps this is something that is intended for an upcoming version
of Postgres.

>On Fri, 7 Jan 2000, Richard Walker wrote:
> >
> > In SQLServer, you can do this:
> >
> > CREATE TABLE fish (
> >     fishID INTEGER IDENTITY (100, 1) NOT NULL,
> >     fishName VARCHAR(32) NOT NULL
> > );
> >
> > When inserting into that table, you don't mention the first field
> > and it will automatically use add 1 to the last value in that field,
> > starting with 100 for the first record.
> > If you wanted it to start at 25 and increment by 5, you'd put
> > fishID INTEGER IDENTITY (25, 5) NOT NULL.
> >
> > I'd like to do something similar to this in PostgreSQL, but the
> > closest I can get requires that I mention the implicit sequence which
> > seems unneccessary hassle:
> >
> > CREATE TABLE fish (
> >     fishID INT4 SERIAL
> >     fishName VARCHAR(32) NOT NULL
> > );
> >
> > SELECT setval('fish_fishID_seq',99);
> >
> > (Incrementing by 1 is fine by me).
> > Is there any way I can do something like:
> > fishID INT4 SERIAL (100, 1)
> > or
> > fishID INT4 SERIAL (START 100)   ?
> >
> > - Rick

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2000-01-09 23:02 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-01-07 02:35 Serial field starting at 100 ? Richard Walker <solar92@hotmail.com>
2000-01-07 15:56 ` Vladimir Terziev <vlady@school.digsys.bg>
2000-01-09 23:02 Re: [SQL] Serial field starting at 100 ? Richard Walker <solar92@hotmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox