Re: SOLUTION: (was : Getting the sequence from pg to insert nexts data )

Поиск
Список
Период
Сортировка
От Paul Thomas
Тема Re: SOLUTION: (was : Getting the sequence from pg to insert nexts data )
Дата
Msg-id 20030622115050.A4067@bacon
обсуждение исходный текст
Ответ на SOLUTION: (was : Getting the sequence from pg to insert nexts data )  ("Rodrigo F. Baroni" <rodrigobaroni@yahoo.com.br>)
Список pgsql-jdbc
On 22/06/2003 10:58 Rodrigo F. Baroni wrote:
>
>    Hello all,
>
>       I got resolv the problem :
>
> >     I'm doing a application using jdbc to connect
> > with
> > a remote postgres database.
> >
> >     One of the tables use a sequence value. My doubt
> > is about how to get the last value of sequence to
> > put
> > in my form table index to follow the insert others
> > values.
> >
>
>       I found at list archive :
> -------------------------------------
>    "
>       First "SELECT nextval('usuario_id_usuario_seq')"
> and store that value.
> Then, "INSERT INTO USUARIO(nombre, passwd, tipo,
> correo)
>     VALUES('tania','aaaaa', $id,
> 'tanitamile@yahoo.com');" where $id is the
> value you stored before.>

That's the way I do it. The other way is to define the column as type
serial and let the database generate the default value:

INSERT INTO USUARIO(nombre, passwd, correo)
VALUES('tania','aaaaa','tanitamile@yahoo.com')
If you need to get the generated key you can do this with SELECT
currval('...') but note that this will only work reliably within the same
tranaction.

HTH


--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Rodrigo F. Baroni"
Дата:
Сообщение: SOLUTION: (was : Getting the sequence from pg to insert nexts data )
Следующее
От: "Kallol Nandi"
Дата:
Сообщение: Re: Urgent : JDBC problem in PostgreSql for Linux