Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8bLR-0001Vf-Py for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 01:57:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8bLO-0006W0-0B for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 01:57:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8bLN-0006Vs-Fd for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2019 01:57:37 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8bLK-0002NU-Dg for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2019 01:57:36 +0000 Received: by mail-qt1-x841.google.com with SMTP id z16so12837444qtn.4 for ; Mon, 25 Mar 2019 18:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=CL7mNKRF0eEsSK7aY2RA3dUyqPVa1WN199niy/Z4uHM=; b=dF36VoNhFaTaTJ2zB0R85UYlScrVJ27SXvVaVgzNuMPVJ1rZjOS/6Qs/7YmotSvHP1 lGZsUchxP9xHwMgs3LWYnFbZYrLxEyvXsD45i6EP7tQW4cy57CC9IcDOO8e3iSTtTIkz Jaq06gqY6jqmR0fedUd2FYInGV5auJ8FrmhbjKVpmXQEqRTV5HC07LzcWPDRxXX19f6j jTp6O1Ip5qFVFOcxlXSs3TNSNWvMMUltr1h33BRrAZzeQzPiJpfprCycuZ9Cjt0x8hMu YJEFdtIdPUSWVbcqYX5kwq4tYJZukV2yo0OfAWMVs4UZ1sASH77L8GoYmG05f/M6+slJ AeWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=CL7mNKRF0eEsSK7aY2RA3dUyqPVa1WN199niy/Z4uHM=; b=knEQmr2L5hOMiSMKLarYbs0cYRibp4iKKxWSA46U46QxMtlA+HwOFwr4zTpMvk0yiR 6PVrNWld4T+bOSxNygAhxAfQw1Ay4ZcUy24Uj2SRCuQVvEJiuvciSkxW/qhJ7V1vEGn+ Cdlc46/L1yrhtBcu2drzv+nrKfsM90B+vXv2qBgo/VnP0igZg9+TtORXn8uHHNHxE6l4 L43B8xlBTmvH8IVxyHxpwoE4dTJabVMftMje7r1nqeYrUQ+HZbvs4y2inTgHbzPr6Ufp kH5aPQLmJ6bNlbU7oH7eiMI7HWSDgYT8UqZou6aEKdCQqylCyvN5lcOI6srl8WQptzGC dEWQ== X-Gm-Message-State: APjAAAXQl2yoCmXeG3ZweqFt4f205FGL+sv/EADRb3yps/9Cm6R9ohoF 3Nzcnceq5M8Bk1U55Ejz1midrw== X-Google-Smtp-Source: APXvYqz2QWSKG3rZRnGVhQAyLnhZBZWLg31MMEM52SdbneOIDm8dJSu0luI7VKrYeHH59jHs+D70kQ== X-Received: by 2002:a0c:afb0:: with SMTP id s45mr8262779qvc.151.1553565453477; Mon, 25 Mar 2019 18:57:33 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([201.186.80.67]) by smtp.gmail.com with ESMTPSA id q75sm10628134qke.17.2019.03.25.18.57.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2019 18:57:32 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 385B21205F1; Mon, 25 Mar 2019 22:57:29 -0300 (-03) Date: Mon, 25 Mar 2019 22:57:29 -0300 From: Alvaro Herrera To: Peter Eisentraut Cc: Amit Langote , Michael Paquier , Robert Haas , Tom Lane , PostgreSQL Hackers Subject: Re: psql display of foreign keys Message-ID: <20190326015729.GA3118@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190325223852.GA2815@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Mar-25, Alvaro Herrera wrote: > v9 attached; this one's final AFAICT. Actually, I propose this fixup. It doesn't change the current output, but of course it affects how this works with my patch in https://postgr.es/m/20190321215420.GA22766@alvherre.pgsql The v9 patch does not show anything for the partitions of the referenced partitioned table; with this one it shows like this -- verify psql behaves sanely \d droppk Partitioned table "regress_fk.droppk" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | not null | Partition key: RANGE (a) Indexes: "droppk_pkey" PRIMARY KEY, btree (a) Referenced by: TABLE "dropfk" CONSTRAINT "dropfk_a_fkey" FOREIGN KEY (a) REFERENCES droppk(a) Number of partitions: 3 (Use \d+ to list them.) \d droppk21 Table "regress_fk.droppk21" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | not null | Partition of: droppk2 FOR VALUES FROM (1000) TO (1400) Indexes: "droppk21_pkey" PRIMARY KEY, btree (a) Referenced by: TABLE "dropfk" CONSTRAINT "dropfk_a_fkey" FOREIGN KEY (a) REFERENCES droppk(a) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --cNdxnHkX5QqsyA0e Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="fixup.patch" commit 12642d9ff66a2661d4f707cb15b0c3de6a9e1d4e Author: Alvaro Herrera AuthorDate: Mon Mar 25 22:50:59 2019 -0300 CommitDate: Mon Mar 25 22:51:15 2019 -0300 fixup diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index fc404bbaab8..91f2306734e 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2489,11 +2489,12 @@ describeOneTableDetails(const char *schemaname, printfPQExpBuffer(&buf, "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n" " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n" - " FROM pg_catalog.pg_constraint c LEFT JOIN \n" - " pg_catalog.pg_partition_ancestors(c.confrelid) ON (true)\n" - " WHERE confrelid = '%s' AND contype = 'f' AND conparentid = 0\n" + " FROM pg_catalog.pg_constraint c\n" + " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n" + " UNION ALL VALUES (regclass '%s'))\n" + " AND contype = 'f' AND conparentid = 0\n" "ORDER BY conname;", - oid); + oid, oid); } else { --cNdxnHkX5QqsyA0e--