Re: [PATCH] psql: add \dcs to list all constraints - Mailing list pgsql-hackers

From Cary Huang
Subject Re: [PATCH] psql: add \dcs to list all constraints
Date
Msg-id 19eb2df5fa0.43034f3c3151107.3042967838443745451@highgo.ca
Whole thread
In response to Re: [PATCH] psql: add \dcs to list all constraints  (Tatsuro Yamada <yamatattsu@gmail.com>)
List 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




pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [PATCH v5] pg_stat_statements: Add last_execution_start column
Next
From: Nathan Bossart
Date:
Subject: fix prev link in docs