Received: from localhost (pluto.hub.org [200.46.204.4]) by postgresql.org (Postfix) with ESMTP id 40FFD9FA0FE for ; Thu, 2 Nov 2006 19:18:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.4]) (amavisd-new, port 10024) with ESMTP id 00432-10 for ; Thu, 2 Nov 2006 19:18:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by postgresql.org (Postfix) with ESMTP id 643C29F9EEC for ; Thu, 2 Nov 2006 19:18:44 -0400 (AST) Received: from zeus (12-207-18-83.client.mchsi.com[12.207.18.83]) by sccmmhc91.asp.att.net (sccmmhc91) with ESMTP id <20061102231842m9100ekdhue>; Thu, 2 Nov 2006 23:18:42 +0000 From: Peter Hanson Reply-To: lists@pkhanson.com To: pgsql-sql@postgresql.org Subject: Re: Determining correct table order for insert or drop statements to satisfy foreign keys Date: Thu, 2 Nov 2006 17:16:48 -0600 User-Agent: KMail/1.9.1 References: <200611021343.31622.lists@pkhanson.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200611021716.49044.lists@pkhanson.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/25 X-Sequence-Number: 26677 Hi Aaron, I'm using PHP5 as the programming language. Thanks, Pete On Thursday 02 November 2006 16:58, Aaron Bono wrote: > On 11/2/06, Peter Hanson wrote: > > 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. > > What programming language are you using? Many languages provide mechanisms > to ask the database for metadata about tables including primary keys, > indexes, data types and foreign keys. That is one option for you.