Re: UNIQUE INDEX and SEQUENCE

From: Daniel Serodio <daniel(at)checkforte(dot)com(dot)br>
To: tania gutierrez <tanitamile(at)yahoo(dot)com>
Cc: PostgreSQL JDBC List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: UNIQUE INDEX and SEQUENCE
Date: 2003-02-27 14:50:45
Message-ID: 1046357444.2678.16.camel@kelly.ckf
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

See comments below;

On Thu, 2003-02-27 at 11:37, tania gutierrez wrote:
> hello poststoneware friends
>
> I need orientacion stops: another form to insert in
> the table
> proximo value of sequencia for the id_usuario.
>
> and as I use usuary create UNIQUE INDEX
> usuario_id_usuario_pk on usuario (id_usuario);
>
>
> //*************
> CREATE SEQUENCE usuario_id_usuario_seq start 1
> increment 1 maxvalue 2147483647 minvalue 1 cache 1;
>
> create table usuario(
> id_usuario int4 DEFAULT
> nextval('usuario_id_usuario_seq'::text) NOT NULL,
> nombre text not null,
> passwd text not null,
> tipo integer not null,
> correo text,
> Constraint usuario_pk Primary Key (id_usuario)
> );
>
> create UNIQUE INDEX usuario_id_usuario_pk on usuario
> (id_usuario);
>
> //*************************
> for insert a values:
>
> insert into usuario(nombre, passwd, tipo,
> correo)values ('tania','aaaaaa', 1,
> 'tanitamile(at)yahoo(dot)com');
>
> //*******************************
> thanks

First "SELECT nextval('usuario_id_usuario_seq')" and store that value.
Then, "INSERT INTO USUARIO(nombre, passwd, tipo, correo)
VALUES('tania','aaaaa', $id, 'tanitamile(at)yahoo(dot)com');" where $id is the
value you stored before.

--
[]'s
Daniel Serodio
CheckForte 5582-6016

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Vernon Wu 2003-02-27 15:19:01 Re: sample JSP code connecting to PostgreSQL
Previous Message tania gutierrez 2003-02-27 14:37:14 UNIQUE INDEX and SEQUENCE