From: Peter Hanson <lists@pkhanson.com>
To: pgsql-sql@postgresql.org
Subject: Determining correct table order for insert or drop statements to satisfy foreign keys
Date: Thu, 2 Nov 2006 13:43:31 -0600
Message-ID: <200611021343.31622.lists@pkhanson.com> (raw)
Hello,
First, sorry if this has already been covered, though I didn't find anything
similar in the archives. Also sorry if this is the wrong list for this type
of question, though it seemed to be the most relevant list for this question.
On to the question:
I'm writing a simple import script that reads in an excel file that a customer
fills out. Each worksheet represents a different table and the tables' fields
are columns in each worksheet.
The tables represented in the file are variable, I have no idea what table
combinations will be in the excel file when it's sent to the script.
What I need is a way for the script to determine what order it should process
the worksheets in the excel file.
For example, you have this table structure (each table would be a worksheet):
PERSON (1) <--> (many) ORDER (1) <--> (many) ORDER_ITEM
Obviously, the people would have to be inserted first, then the orders, and
finally the items, to keep the foreign keys between the tables happy.
Is there a mechanism in PostgreSQL that would tell me this order? Or is it
something that would have to be assembled from analyzing the schema? Anybody
needed to perform an operation like this before? Any help/direction would be
greatly appreciated.
Thanks for your time and help,
Pete Hanson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: lists@pkhanson.com
Subject: Re: Determining correct table order for insert or drop statements to satisfy foreign keys
In-Reply-To: <200611021343.31622.lists@pkhanson.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox