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: Multiple inserts into 2 tables with FKs
Date: 2007-07-03 10:17:16
Message-ID: 468A222C.6050305@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi

I have 2 tables, one containing unique filenames, the other containing
paths to those files. Paths are spread over multiple hosts (SMB shared
files). The layout is like this:

Column | Type |
Modifiers
---------------+------------------------+-----------------------------------------------------------------
filename_id | integer | not null default
nextval('filenames_filename_id_seq'::regclass)
filename_name | character varying(512) |
Indexes:
"filenames_pkey" PRIMARY KEY, btree (filename_id)
"filenames_filename_name_key" UNIQUE, btree (filename_name)

Column | Type |
Modifiers
------------------+-------------------------+---------------------------------------------------------
path_id | integer | not null default
nextval('paths_path_id_seq'::regclass)
path_filename_id | integer |
path | character varying(2048) |
Foreign-key constraints:
"paths_path_filename_id_fkey" FOREIGN KEY (path_filename_id)
REFERENCES filenames(filename_id)

The thing is, these tables will be update regularly (once a day, at
least). All hosts on this SMB network are indexed, their files and paths
added to the database if they aren't there already. My question is, how
do I actually go about doing this? How do I find out which filename_id
to insert into the paths table?

Greetings,
Tiemo.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Loredana Curugiu 2007-07-03 12:25:51 Re: dblink inside plpgsql function
Previous Message Bart Degryse 2007-07-03 09:45:53 Re: dblink inside plpgsql function