Skip site navigation (1) Skip section navigation (2)

Re: Multiple inserts into 2 tables with FKs

From: Tiemo Kieft <t(dot)kieft(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple inserts into 2 tables with FKs
Date: 2007-07-03 20:48:40
Message-ID: 468AB628.9060004@gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Josh Tolley wrote:
> If I understand the problem correctly, you might do something like
> this (if you're using 8.2 and have INSERT...RETURNING):
>
> INSERT INTO filename (filename_name) VALUES ('some_filename_here')
> RETURNING filename_id;
>
> This will return a value, for instance, 10. Then you'd do this:
>
> INSERT INTO path (path_filename_id, path) VALUES (10, 'your_path_here');
But what if the filename is already in the filenames table? It will give 
an error due to duplicate values, so I'll have to do a SELECT after 
that? I was kind of hoping there was a somewhat more elegant solution to 
this.

In response to

pgsql-novice by date

Next:From: David MonarchiDate: 2007-07-04 20:22:56
Subject: COPY and index updating
Previous:From: Josh TolleyDate: 2007-07-03 17:39:46
Subject: Re: Multiple inserts into 2 tables with FKs

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group