Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aZ8qO-00071l-UO for pgsql-sql@arkaria.postgresql.org; Fri, 26 Feb 2016 03:13:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aZ8qO-0005RX-Cs for pgsql-sql@arkaria.postgresql.org; Fri, 26 Feb 2016 03:13:28 +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 1aZ8pN-0004MB-LY for pgsql-sql@postgresql.org; Fri, 26 Feb 2016 03:12:25 +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 1aZ8pK-0007AU-Gr for pgsql-sql@postgresql.org; Fri, 26 Feb 2016 03:12:24 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 506B920A33 for ; Thu, 25 Feb 2016 22:12:21 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Thu, 25 Feb 2016 22:12:21 -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=Wea/3TWUwjgOwCVO9rQbhsfqNdc=; b=KRVJl9 hG3ReJGBJ4GrRpT4mbGpPBGEvJQsm5hjtDmHEAQdEdhbmYpwRCjHElWRmrkaA/eU SoZ8x9VvPk1lBOAbM0KnToObkJBLzc+OC2RW8RJ/5fBeKNGi8Sg1yR47wsnTaHGZ 0VtXFY+KNRZO1FHf8KgGMSo213KvnmKcXmZ1s= 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=Wea/3TWUwjgOwCV O9rQbhsfqNdc=; b=Zq09K0V7bny5YLyr6Ef4iF9CAGebCDjghuJA5hDWwE2Aq+0 Lq/1v5uXPdL/LG8uhN7yRZ8F++hDH7DNhuV6/VT1Aw89qDhHPkVS+dJ3Rk2zSp+p HTXVezLNfupBjC9nBAkqfAWAxTdHV7r6vKziJe2sdhDBzusrkgVkIhWjYhXk= X-Sasl-enc: zAKk4L0OOBoU+AJP0iCM6Z+4l3j4MQluFnfjSXLBPge1 1456456340 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 BCB9D6801C3; Thu, 25 Feb 2016 22:12:20 -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> From: Adrian Klaver Message-ID: <56CFC24A.6030508@aklaver.com> Date: Thu, 25 Feb 2016 19:11:06 -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.0 (--) 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 05:36 PM, David Binney wrote: > Hey Adrian, > > In this case the type is just being referenced from the > "constraint_type" column in the "information_schema.table_constraints". > > select * from information_schema.table_constraints tc where table_name = > 'products'; > > Hopefully that helps My confusion is that in your original post you said: "... get the same dataset from mysql and postgres ..." and what you are asking for is different datasets. Just trying to pin down exactly the data you need and whether it really is the same for MySQL and Postgres or if it is different? > > On Fri, 26 Feb 2016 at 11:06 Adrian Klaver > wrote: > > On 02/25/2016 04:56 PM, David Binney wrote: > > Hey Adrian, > > > > 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 > > > > Those are the needed columns, as the end resultset. > > But that is different then what you are asking from the MySQL query: > > http://dev.mysql.com/doc/refman/5.7/en/information-schema.html > > There is no constraint_type in the information_schema tables you > reference in the MySQL query, unless I am missing something. > > > > > On Fri, 26 Feb 2016 at 10:51 Adrian Klaver > > > >> wrote: > > > > On 02/25/2016 04:38 PM, David Binney wrote: > > > Hey guys, > > > > > > I am having a tricky problem which I have not needed to > solve before. > > > Basically one of the php frameworks I am using needs to > get the same > > > dataset from mysql and postgres but I am not sure how to > do the > > joins. > > > > > > Below i have the mysql version of the query which work ok, > and after > > > that i have my attempt at the postgresql version, which is > not joined > > > correctly. Any help would be greatly appreciated, and in the > > meantime i > > > will keep guessing which columns need to be joined for > those three > > > tables, but I am thinking there could be a view or > something to > > solve my > > > problem straight away?? > > > > The * in your MySQL query hides what it is you are trying > retrieve. > > > > So what information are you after? > > > > Or to put it another way, what fails in the Postgres version? > > > > > > > > -------mysql working version---------- > > > SELECT > > > * > > > FROM > > > information_schema.key_column_usage AS kcu > > > INNER JOIN information_schema.referential_constraints AS > rc ON ( > > > kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME > > > AND kcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA > > > ) > > > WHERE > > > kcu.TABLE_SCHEMA = 'timetable' > > > AND kcu.TABLE_NAME = 'issues' > > > AND rc.TABLE_NAME = 'issues' > > > > > > ---- postgresql partial working version-------------- > > > > > > 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 = 'issues' > > > AND rc.constraint_schema = 'public' > > > AND tc.constraint_type = 'FOREIGN KEY' > > > ORDER BY > > > rc.constraint_name, > > > cu.ordinal_position; > > > > > > -- > > > Cheers David Binney > > > > > > -- > > Adrian Klaver > > adrian.klaver@aklaver.com > > > > > > -- > > Cheers David Binney > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > -- > Cheers David Binney -- 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