Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aZK98-00023P-Kh for pgsql-sql@arkaria.postgresql.org; Fri, 26 Feb 2016 15:17:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aZK98-00048E-7l for pgsql-sql@arkaria.postgresql.org; Fri, 26 Feb 2016 15:17:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aZK88-0002cW-GI for pgsql-sql@postgresql.org; Fri, 26 Feb 2016 15:16:32 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aZK86-0005RN-1s for pgsql-sql@postgresql.org; Fri, 26 Feb 2016 15:16:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0F3532095B for ; Fri, 26 Feb 2016 10:16:29 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Fri, 26 Feb 2016 10:16:29 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=SJ8PczbMyucsfbiBWoKWS9ceoME=; b=QsUlcK TUoDJ9Xa23FSFE7MQCo7to24H7vu6YUd1Lghcd7HV5OlHL+gidL1pwhAQR+vwOcO aCB6U5wUJDlciaGxYFP7AP7FnFVs6kkyqkw1KgtrFUNa2KrvAJUXoJZ9lyWyElNV YdXK2cqAgqcSZoQ5H0MlObU+vlmM/XirQ8PIU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=SJ8PczbMyucsfbi BWoKWS9ceoME=; b=QCWwRJkLYOOLlt6nKqnOkRu3rGAGEsLtL8i6OtEozR+P6rs K+eWHGlgTHb798DavJ0L5qbPltQb+LjQ3QlfeksA598pOG7jbpIdDgRr4fPF6hTG JYu+k32ZFurtS/WsZaxViPR+mt+p8UD6JVXxO5EHSLMXlowHZcMkpJI+webU= X-Sasl-enc: aX+wZJDWDWdRTkBwQO4VLpt2uuINWBFtps6DoyMGQ7cZ 1456499788 Received: from [192.168.1.2] (174-21-70-246.tukw.qwest.net [174.21.70.246]) by mail.messagingengine.com (Postfix) with ESMTPA id 61EFCC00013; Fri, 26 Feb 2016 10:16:28 -0500 (EST) Subject: Re: Query about foreign key details for php framework To: David Binney , pgsql-sql@postgresql.org References: <56CFA136.4000508@aklaver.com> <56CFA4E1.8040204@aklaver.com> <56CFC24A.6030508@aklaver.com> From: Adrian Klaver Message-ID: <56D06C02.5040107@aklaver.com> Date: Fri, 26 Feb 2016 07:15:14 -0800 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 02/25/2016 07:19 PM, David Binney wrote: > Ah sorry adrian, > > I am a little in the dark as well since this is just a broken piece of > ORM i am attempting to fix, in the framework. So, maybe if you could > help to reproduce that select list as a start that would be great. But, > I am suspecting they were trying to pull similar datasets from mysql or > postgres as an end goal. > Alright I ran the Postgres query you provided and it threw an error: ERROR: missing FROM-clause entry for table "cu" LINE 26: cu.ordinal_position; in the ORDER BY clause. Changing cu.ordinal_position to kcu.ordinal_position obtained a result when run for a table in one of my databases: production=# select rc.constraint_name AS name, tc.constraint_type AS type, kcu.column_name, rc.match_option AS match_type, rc.update_rule AS on_update, rc.delete_rule AS on_delete, kcu.table_name AS references_table, kcu.column_name AS references_field, kcu.ordinal_position FROM (select distinct * from information_schema.referential_constraints) rc JOIN information_schema.key_column_usage kcu ON kcu.constraint_name = rc.constraint_name AND kcu.constraint_schema = rc.constraint_schema JOIN information_schema.table_constraints tc ON tc.constraint_name = rc.constraint_name AND tc.constraint_schema = rc.constraint_schema AND tc.constraint_name = rc.constraint_name AND tc.table_schema = rc.constraint_schema WHERE kcu.table_name = 'projection' AND rc.constraint_schema = 'public' AND tc.constraint_type = 'FOREIGN KEY' ORDER BY rc.constraint_name, kcu.ordinal_position; -[ RECORD 1 ]----+------------ name | con_fkey type | FOREIGN KEY column_name | c_id match_type | NONE on_update | CASCADE on_delete | CASCADE references_table | projection references_field | c_id ordinal_position | 1 -[ RECORD 2 ]----+------------ name | con_fkey type | FOREIGN KEY column_name | c_id match_type | NONE on_update | CASCADE on_delete | CASCADE references_table | projection references_field | c_id ordinal_position | 1 -[ RECORD 3 ]----+------------ name | pno_fkey type | FOREIGN KEY column_name | p_item_no match_type | NONE on_update | CASCADE on_delete | CASCADE references_table | projection references_field | p_item_no If this is not the desired result, then we will need more information. -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql