pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
system maintained keys
5+ messages / 4 participants
[nested] [flat]

* system maintained keys
@ 2001-10-15 15:43 Stefan Lindner <lindner@visionet.de>
  2001-10-19 17:46 ` Re: system maintained keys Josh Berkus <josh@agliodbs.com>
  2001-10-19 18:57 ` Re: system maintained keys Jason Earl <jdearl@yahoo.com>
  2001-10-19 20:34 ` Re: system maintained keys Joel Burton <joel@joelburton.com>
  2001-10-21 19:51 ` Re: system maintained keys Stefan Lindner <lindner@visionet.de>
  0 siblings, 4 replies; 5+ messages in thread

From: Stefan Lindner @ 2001-10-15 15:43 UTC (permalink / raw)
  To: pgsql-sql

Is there any way to get system maintained keys from postgres? e.g. to
have a table with a primary key column (varchar or int) and let postgres
chose the next unique value for this column?





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

* Re: system maintained keys
  2001-10-15 15:43 system maintained keys Stefan Lindner <lindner@visionet.de>
@ 2001-10-19 17:46 ` Josh Berkus <josh@agliodbs.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Josh Berkus @ 2001-10-19 17:46 UTC (permalink / raw)
  To: Stefan Lindner <lindner@visionet.de>; pgsql-sql

Stefan,

> Is there any way to get system maintained keys from postgres? e.g. to
> have a table with a primary key column (varchar or int) and let
> postgres
> chose the next unique value for this column?

Please address future questions of this type to the PGSQL-NOVICE list.
PGSQL-SQL is for more advanced SQL issues.

Yes, you can do this easily,  Please see:
http://www.postgresql.org/idocs/index.php?datatype.html#DATATYPE-NUMERIC
Look at secion 3.1.1 on the page.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



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

* Re: system maintained keys
  2001-10-15 15:43 system maintained keys Stefan Lindner <lindner@visionet.de>
@ 2001-10-19 18:57 ` Jason Earl <jdearl@yahoo.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Jason Earl @ 2001-10-19 18:57 UTC (permalink / raw)
  To: Stefan Lindner <lindner@visionet.de>; pgsql-sql

Check out the SERIAL type.  It does precisely what you
want.  An idea as to how this is used would be like
this:

CREATE TABLE foo (
  prim_key     SERIAL PRIMARY KEY,
  bar          text
);

I tend to create sequences by hand like this:

CREATE SEQUENCE my_sequence_seq;

And then I create my table with a definition like
this:

CREATE TABLE foo (
  prim_key     int DEFAULT nextval('my_sequence_seq')
                 PRIMARY KEY,
  bar          text,
);

But that's just because I have been using PostgreSQL
long enough that it didn't have the SERIAL type when I
started.  The SERIAL type is just syntactic sugar for
what I generally do the long way.

Either way you simply pretend that the column isn't
there when you do inserts (unless you know what you
are doing) like so:

INSERT INTO foo (bar) VALUES ('hello');
INSERT INTO foo (bar) VALUES ('goodbye');

And then when you select you get:

processdata=> SELECT * FROM foo;
 prim_key |   bar   
----------+---------
        1 | hello
        2 | goodbye
(2 rows)

I hope that is helpful,
Jason Earl

--- Stefan Lindner <lindner@visionet.de> wrote:
> Is there any way to get system maintained keys from
> postgres? e.g. to
> have a table with a primary key column (varchar or
> int) and let postgres
> chose the next unique value for this column?
> 
> 
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com



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

* Re: system maintained keys
  2001-10-15 15:43 system maintained keys Stefan Lindner <lindner@visionet.de>
@ 2001-10-19 20:34 ` Joel Burton <joel@joelburton.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Joel Burton @ 2001-10-19 20:34 UTC (permalink / raw)
  To: Stefan Lindner <lindner@visionet.de>; +Cc: pgsql-sql

On Mon, 15 Oct 2001, Stefan Lindner wrote:

> Is there any way to get system maintained keys from postgres? e.g. to
> have a table with a primary key column (varchar or int) and let postgres
> chose the next unique value for this column?

\h CREATE SEQUENCE  will give syntax, or look up SEQUENCES and SERIAL data
type in the documentation.

-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant




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

* Re: system maintained keys
  2001-10-15 15:43 system maintained keys Stefan Lindner <lindner@visionet.de>
@ 2001-10-21 19:51 ` Stefan Lindner <lindner@visionet.de>
  3 siblings, 0 replies; 5+ messages in thread

From: Stefan Lindner @ 2001-10-21 19:51 UTC (permalink / raw)
  To: pgsql-sql

Thank you very much! Thanks to all who answered! An I will never again ask
silly questions here :-)
"Stefan Lindner" <lindner@visionet.de> schrieb im Newsbeitrag
news:9qf06v$20bh$1@news.tht.net...
> Is there any way to get system maintained keys from postgres? e.g. to
> have a table with a primary key column (varchar or int) and let postgres
> chose the next unique value for this column?
>
>





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


end of thread, other threads:[~2001-10-21 19:51 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-15 15:43 system maintained keys Stefan Lindner <lindner@visionet.de>
2001-10-19 17:46 ` Josh Berkus <josh@agliodbs.com>
2001-10-19 18:57 ` Jason Earl <jdearl@yahoo.com>
2001-10-19 20:34 ` Joel Burton <joel@joelburton.com>
2001-10-21 19:51 ` Stefan Lindner <lindner@visionet.de>

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