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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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