Re: [PATCH] psql: add \dcs to list all constraints
Cary Huang <cary.huang@highgo.ca>
From: Cary Huang <cary.huang@highgo.ca>
To: "Tatsuro Yamada" <yamatattsu@gmail.com>
Cc: "Álvaro Herrera" <alvherre@kurilemu.de>, "Chao Li" <li.evan.chao@gmail.com>, "Tom Lane" <tgl@sss.pgh.pa.us>, "Jim Jones" <jim.jones@uni-muenster.de>, "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2026-06-10T18:50:44Z
Lists: pgsql-hackers
Hi
The newly added \dCN meta-command in psql does return all constraints correctly,
but it does not properly filter by table name. When a table name is provided as
an argument, the command returns empty results instead of matching constraints
on that table. For example:
-- Setup
CREATE TABLE con_test_table (
id INT PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
-- List all constraints (works correctly)
\dCN
-- List constraints on specific table (returns empty)
\dCN con_test_table
-- Match by constraint name (works correctly)
\dCN con_test_table_pkey
To fix, in "src/bin/psql/describe.c", in the `listConstraints()` function, change:
```
if (!validateSQLNamePattern(&buf, pattern,
true, false,
"n.nspname", "cns.conname", NULL,
NULL, NULL, 3))
```
To:
```
if (!validateSQLNamePattern(&buf, pattern,
true, false,
"n.nspname", "cns.conname", "c.relname",
NULL, NULL, 3))
```
to allow the pattern to match against table names as well.
thanks
Cary Huang
-------------
HighGo Software (Canada)
cary.huang@highgo.ca
www.highgo.ca