pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Poovendran Moodley <poovenm@gmail.com>
To: pgsql-sql@postgresql.org
Subject: SQL INSERT/TRIGGER Help
Date: Mon, 10 Dec 2007 08:36:44 +0200
Message-ID: <b18bbf6f0712092236m48fa2e28s80b7bbb30c80dc22@mail.gmail.com> (raw)

Hi all, I'm not sure how to phrase this question... I have a table that
requires a foreign key of another table - this foreign key is automatically
generated and the key field in the 'foreign' table. So I have the following
situation (kind of):

Table *Observation*

*Time_Stamp* - *primary key*

...

Observation_ID - *foreign key*

Table *Observation_Value*

*Observation_ID* - *primary key*

...

So obviously I need to insert into the table *Observation_Value* first
before I can insert into table *Observation*, but how to I get the
automatically generated foreign key?

I was thinking of using a trigger - when a value is inserted into *
Observation_Value* then add the primary key to a new table (probably a view)
and get that value for insertion into *Observation* then drop temporary
table. I wanted to know if there's an easier way to do this? I can't change
the table structure in any way either.... any help would be appreciated. I'm
not even sure what type of search query I should use to find help on this
topic either...

Regards,
Pooven

view thread (6+ messages)  latest in thread

Message-ID: <b18bbf6f0712092236m48fa2e28s80b7bbb30c80dc22@mail.gmail.com>
Permalink:  ../b18bbf6f0712092236m48fa2e28s80b7bbb30c80dc22@mail.gmail.com/
Also on:    postgresql.org/message-id/b18bbf6f0712092236m48fa2e28s80b7bbb30c80dc22@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: poovenm@gmail.com
  Subject: Re: SQL INSERT/TRIGGER Help
  In-Reply-To: <b18bbf6f0712092236m48fa2e28s80b7bbb30c80dc22@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox