Re: Multiple inserts into 2 tables with FKs - Mailing list pgsql-novice

From Tiemo Kieft
Subject Re: Multiple inserts into 2 tables with FKs
Date
Msg-id 468AB628.9060004@gmail.com
Whole thread Raw
In response to Re: Multiple inserts into 2 tables with FKs  ("Josh Tolley" <eggyknap@gmail.com>)
List 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.

pgsql-novice by date:

Previous
From: "Josh Tolley"
Date:
Subject: Re: Multiple inserts into 2 tables with FKs
Next
From: "David Monarchi"
Date:
Subject: COPY and index updating