Re: Primary Key with serial the solution?

From: "x asasaxax" <xanaruto(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Primary Key with serial the solution?
Date: 2008-04-01 11:26:44
Message-ID: 91495cb0804010426o51050a8x741b0def49f3b62d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How about if i do this inside a procedure:

SELECT setval('sequence',(SELECT max(id) FROM table)) INTO variable;
insert into table values(variable, ..., ...); ?

Will this be transactional? Cause, they say that setval is a command
that its transactional. Using this way i
don´t will need to use a sequence anymore. Is that correct?

Thanks you all.

2008/3/31, x asasaxax <xanaruto(at)gmail(dot)com>:
>
> can anyone do a example for me.. an explain how it works?
>
> Thanks a lot
>
>
> 2008/3/29, Berend Tober <btober(at)ct(dot)metrocast(dot)net>:
> >
> > x asasaxax wrote:
> > > I have the following table create table product(cod serial,
> > user_cod
> > > bigint, constraint product_fk Foreign Key(user_cod) references
> > user(cod),
> > > constraint product_pk Primary Key(cod, user_cod));
> > >
> > > What i want to happend is that:
> > > user_cod cod
> > > 1 1
> > > 1 2
> > > 1 3
> > > 2 1
> > > 3 1
> > > 3 2
> > >
> > > Can serial do that? ...
> >
> > No.
> >
> > > ...what can i do to make this happen?
> >
> >
> > http://archives.postgresql.org/pgsql-general/2006-08/msg00744.php
> >
> >
> >
>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2008-04-01 11:32:04 Re: HOWTO caching data across function calls: temporary tables, cursor?
Previous Message josep porres 2008-04-01 10:54:53 Re: minimum and maximum functions