pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: psql display of foreign keys
Date: Mon, 25 Mar 2019 22:57:29 -0300
Message-ID: <20190326015729.GA3118@alvherre.pgsql> (raw)
In-Reply-To: <20190325223852.GA2815@alvherre.pgsql>

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

Attachments:

  [text/x-diff] fixup.patch (1.2K, ../20190326015729.GA3118@alvherre.pgsql/2-fixup.patch)
  download | inline diff:
commit 12642d9ff66a2661d4f707cb15b0c3de6a9e1d4e
Author:     Alvaro Herrera <alvherre@alvh.no-ip.org>
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
 			{

view thread (30+ messages)  latest in thread

Message-ID: <20190326015729.GA3118@alvherre.pgsql>
Permalink:  ../20190326015729.GA3118@alvherre.pgsql/
Also on:    postgresql.org/message-id/20190326015729.GA3118@alvherre.pgsql

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, peter.eisentraut@2ndquadrant.com, Langote_Amit_f8@lab.ntt.co.jp, michael@paquier.xyz, robertmhaas@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: psql display of foreign keys
  In-Reply-To: <20190326015729.GA3118@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox