Re: easy way to insert same value into 2 columns - Mailing list pgsql-general

From Sebastian Boeck
Subject Re: easy way to insert same value into 2 columns
Date
Msg-id 3F8E7B1D.9040407@freenet.de
Whole thread Raw
In response to Re: easy way to insert same value into 2 columns  (Jacob Vennervald <jvennervald@proventum.net>)
List 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


pgsql-general by date:

Previous
From: Jacob Vennervald
Date:
Subject: Re: easy way to insert same value into 2 columns
Next
From: Csaba Nagy
Date:
Subject: Re: easy way to insert same value into 2 columns