Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id ACB209FA646 for ; Thu, 2 Nov 2006 18:58:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 92457-07 for ; Thu, 2 Nov 2006 18:58:09 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 49C3F9FA5F0 for ; Thu, 2 Nov 2006 18:58:07 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so238866ugf for ; Thu, 02 Nov 2006 14:58:06 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=L5z8R1taAOVoMneM7Oy/JSIPcwjY6XSSmAFTqjHY0/KTCjQHVE6VlRkYMTNzYdjU/vAe4v3vu8Hqk16e2AC+Yx07i+UmacEiflyUqzrSH6n8g7mjrA2wRizTrm82tTCu7GKFIy2O8kMB1QiyoqmRu9CB4amrAtI4nbOsLRu2ujg= Received: by 10.78.142.14 with SMTP id p14mr1581864hud.1162508285176; Thu, 02 Nov 2006 14:58:05 -0800 (PST) Received: by 10.78.136.6 with HTTP; Thu, 2 Nov 2006 14:58:05 -0800 (PST) Message-ID: Date: Thu, 2 Nov 2006 16:58:05 -0600 From: "Aaron Bono" To: lists@pkhanson.com Subject: Re: Determining correct table order for insert or drop statements to satisfy foreign keys Cc: pgsql-sql@postgresql.org In-Reply-To: <200611021343.31622.lists@pkhanson.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_9107_19647692.1162508285006" References: <200611021343.31622.lists@pkhanson.com> X-Google-Sender-Auth: d30ea90c5d017a6b X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/24 X-Sequence-Number: 26676 ------=_Part_9107_19647692.1162508285006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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. -- ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com http://codeelixir.com ================================================================== ------=_Part_9107_19647692.1162508285006 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/2/06, Peter Hanson <lists@pkhanson.com> 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.

--
==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
================================================================== ------=_Part_9107_19647692.1162508285006--