Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B8E0B2E013C for ; Mon, 10 Dec 2007 02:36:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 76213-10 for ; Mon, 10 Dec 2007 02:36:45 -0400 (AST) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.191]) by postgresql.org (Postfix) with ESMTP id 35EF62E013A for ; Mon, 10 Dec 2007 02:36:45 -0400 (AST) Received: by rv-out-0910.google.com with SMTP id l15so1661687rvb for ; Sun, 09 Dec 2007 22:36:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=up/Smmpkl84Y7dCtR0CcJvtA5QCJCFnslrTuEVjSLIE=; b=q8xw24vdNboKz5XPPO5KMviggxJPlUS1mEoVayT+jMxYbYEqLbU8JreQ1TWXQzjnMj800+RqZXI8EK6ee3vzG26y6qLe/Fq6K561+H1fEuamgCDrPbUz6d4J27CTbOSkWHBl21+OXud7g8p53TXnGe64SfhssT0G/yzY7in4OKk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=wQWXlhTXgUwSpYsw/K3XGtplz/6UUNc8gx+jLTy9j7oJ5TFw2sgD9EwzxtvxNqm22OKH+QnUOqtknL0MjxFmr83EoAUpqvR4/WSnx97OBqHlsxmLweaX9U3M74D2kCCTZPhivENsGP0x4RtcBqbA32SDNa7Z4U4dByLHXFGDWwc= Received: by 10.141.153.16 with SMTP id f16mr848556rvo.1197268604248; Sun, 09 Dec 2007 22:36:44 -0800 (PST) Received: by 10.140.128.1 with HTTP; Sun, 9 Dec 2007 22:36:44 -0800 (PST) Message-ID: Date: Mon, 10 Dec 2007 08:36:44 +0200 From: "Poovendran Moodley" To: pgsql-sql@postgresql.org Subject: SQL INSERT/TRIGGER Help MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_10844_7058591.1197268604234" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/30 X-Sequence-Number: 29722 ------=_Part_10844_7058591.1197268604234 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_10844_7058591.1197268604234 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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
------=_Part_10844_7058591.1197268604234--