| From: | Tatsuro Yamada <yamatattsu(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Subject: | Re: [PATCH] psql: add \dcs to list all constraints |
| Date: | 2026-01-16 10:37:00 |
| Message-ID: | CAOKkKFtTtM91n75Jrw+iFuhbg54zS9CRAqn9Ne1FTNAg7Kfhig@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Chao, Jim, and Tom,
On Thu, Jan 15, 2026 at 7:49 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>>> Which do you think is better? Should domain constraints be covered by
\dCN?
>>> I would appreciate your feedback.
>>
>> I had a feeling while reviewing the patch but I didn’t raise it
>> because I was not firm minded. As you ask, this is just my personal
>> opinion, you may ignore if you don’t consider reasonable.
>>
>> This patch claims “constraints”, but it actually only shows table
>> constraints. How, we can see the code comment says "Describes
constraints”,
>> the command message says "List of constraints”, I think that’s where
>> the discussion came from.
>>
>> Maybe an easy way to go is something like renaming the command to \dTCN,
>> making it specific to table constraints.
>
>I just want to add that, I am not sure if “table constraints” is a
>proper group, and I didn’t intend to suggest a new command name as \dTCN.
>My point was to make the feature scope more specific, and make the command
>name better reflect to the scope.
Thank you for your feedback.
As you pointed out, it was indeed inappropriate to exclude some types of
constraints while using the title "list constraints."
To address this issue, I have modified the query to include domain
constraints
in the output. This is included in the v5 patch.
The revised query is shown below.
The main difference from the v4 patch is that the pg_type table is now
joined.
```
SELECT n.nspname AS "Schema",
cns.conname AS "Name" ,
pg_catalog.pg_get_constraintdef(cns.oid, true) AS "Definition",
c.relname AS "Table"
FROM pg_catalog.pg_constraint cns
JOIN pg_catalog.pg_namespace n ON n.oid = cns.connamespace
LEFT JOIN pg_catalog.pg_type t ON t.oid = cns.contypid
LEFT JOIN pg_catalog.pg_class c on c.oid = cns.conrelid
WHERE n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND (
(cns.conrelid <> 0 AND pg_catalog.pg_table_is_visible(cns.conrelid))
OR (cns.contypid > 0 AND pg_catalog.pg_type_is_visible(t.oid))
)
ORDER BY 1, 2, 4;
```
For reference, here is the old query from the v4 patch:
```
SELECT n.nspname AS "Schema",
cst.conname AS "Name" ,
pg_catalog.pg_get_constraintdef(cst.oid) AS "Definition",
c.relname AS "Table"
FROM pg_catalog.pg_constraint cst
JOIN pg_catalog.pg_namespace n ON n.oid = cst.connamespace
JOIN pg_catalog.pg_class c on c.oid = cst.conrelid
WHERE n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND pg_catalog.pg_table_is_visible(cst.conrelid)
ORDER BY 1, 2, 4;
```
Please find attached patch.
Comments and suggestions are welcome.
Regards,
Tatsuro Yamada
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Álvaro Herrera | 2026-01-16 10:41:58 | Re: [PATCH] remove incorrect comment in pg_resetwal.c |
| Previous Message | Soumya S Murali | 2026-01-16 10:29:19 | Re: 001_password.pl fails with --without-readline |