Skip site navigation (1) Skip section navigation (2)

Re: Serial field

From: "Todd T(dot) Fries" <todd(at)fries(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Serial field
Date: 2001-07-13 22:03:49
Message-ID: 20010713170349.C9085@eclipse.fries.net (view raw or flat)
Thread:
Lists: pgsql-novice
Just wanted to chime in here, I'm not on the mailing list so please cc me
any replies.

The techniques you have described I am surprised to not hear the solution
I am employing:

 =# create table foo (id int default nextval('foo_seq'::text),
 (# data text);
CREATE
 =# create sequence foo_seq;
CREATE
 =#

Then if you insert data, the default value will be a sequence that has
several properties to it:

=# \d foo_seq
   Sequence "foo_seq"
   Attribute   |  Type   
---------------+---------
 sequence_name | name
 last_value    | integer
 increment_by  | integer
 max_value     | integer
 min_value     | integer
 cache_value   | integer
 log_cnt       | integer
 is_cycled     | "char"
 is_called     | "char"

=# select * from foo_seq;
 sequence_name | last_value | increment_by | max_value  | min_value | cache_value | log_cnt | is_cycled | is_called 
---------------+------------+--------------+------------+-----------+-------------+---------+-----------+-----------
 foo_seq       |          1 |            1 | 2147483647 |         1 |           1 |       1 | f         | f
(1 row)

=# insert into foo (data) values ('fee');
INSERT 107739 1
=# insert into foo (data) values ('fie');
INSERT 107740 1
=# insert into foo (data) values ('fo');
INSERT 107741 1
=# insert into foo (data) values ('fum');
INSERT 107742 1
=# select * from foo;
 id | data 
----+------
  1 | fee
  2 | fie
  3 | fo
  4 | fum
(4 rows)

=# select * from foo_seq;
 sequence_name | last_value | increment_by | max_value  | min_value | cache_value | log_cnt | is_cycled | is_called 
---------------+------------+--------------+------------+-----------+-------------+---------+-----------+-----------
 foo_seq       |          4 |            1 | 2147483647 |         1 |           1 |      30 | f         | t
(1 row)

=# 

I believe this is how things were meant to be, no?
-- 
Todd Fries .. todd(at)fries(dot)net

pgsql-novice by date

Next:From: Henry HouseDate: 2001-07-14 17:35:06
Subject: Re: Cast question (NULL -> NUMERIC)
Previous:From: Tom LaneDate: 2001-07-13 21:11:25
Subject: Re: Cast question (NULL -> NUMERIC)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group