pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: CIMPOESU Teodor <teo@digiro.net>
To: Patrice DUMAS <pdumas@inforoutes-ardeche.fr>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Unique Number KEY
Date: Fri, 26 Feb 1999 20:25:17 +0200
Message-ID: <36D6E70D.ACF4CB7D@digiro.net> (raw)
References: <000901be61af$7018d800$ce9efea9@blneige>

Patrice DUMAS wrote:

> Hello,
>
> What is the best way, with PostGres, to create a Unique Number Key
> Generator?
>
> For example, I have a STUDENTS table:
> {
>     StudentNumber    integer;
>     StudentName      char[40];
> ...
> }

you have 2 ways to do it:
1. try something like
      CREATE TABLE  STUDENTS(
           studentID  int4 DEFAULT 'int(now())',
          studentName text );
then if you say:
 INSERT INTO STUDENTS (studentName) VALUES ('Patrice DUMAS jr.') ;
you will get an unique ID generated from a timestamp returned by now() .

2. by using a sequence.See \h create sequence and nextval() function.
      This is a better way to get an ordered ID ( with an increment specified
by you).






view thread (4+ messages)  latest in thread

Message-ID: <36D6E70D.ACF4CB7D@digiro.net>
Permalink:  ../36D6E70D.ACF4CB7D@digiro.net/
Also on:    postgresql.org/message-id/36D6E70D.ACF4CB7D@digiro.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: teo@digiro.net, pdumas@inforoutes-ardeche.fr
  Subject: Re: [SQL] Unique Number KEY
  In-Reply-To: <36D6E70D.ACF4CB7D@digiro.net>
  References: <000901be61af$7018d800$ce9efea9@blneige> <36D6E70D.ACF4CB7D@digiro.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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