Re: easy way to insert same value into 2 columns

From: Sebastian Boeck <sebastianboeck(at)freenet(dot)de>
To: Jacob Vennervald <jvennervald(at)proventum(dot)net>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: easy way to insert same value into 2 columns
Date: 2003-10-16 11:03:57
Message-ID: 3F8E7B1D.9040407@freenet.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jacob Vennervald wrote:
>>Thanks a lot, but is it save to use?
>>
>>Do i always get the same value, even if an other insert is changing
>>the sequence >public.zeit_id_seq< just at the same time?
>
> Yes. currval() gives you the last id of the sequence in your session.
> So if others log in and insert more rows it wont affect your session.
>
> Can I ask why you would wanna do that anyway?
>
> Jacob

Sure!

I have several tables with an inheritance hierachy.
The first one (zeit) has a Serialfield called id.
All other tables inherit from this one, so that i have
an absolutely unique id over all tables. But if i want
to reference the id of a table in the middle of the
hierarchy-chain, it won't work, because it's not the
tables own index. Therefore i need an duplicated value.
On this column i can create another index that can be
used as an foreign key by other tables.

Are there any other ways to accomplish this?

Regards

Sebastian

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Csaba Nagy 2003-10-16 11:21:38 Re: easy way to insert same value into 2 columns
Previous Message Jacob Vennervald 2003-10-16 10:53:40 Re: easy way to insert same value into 2 columns