Why there is no records?

Started by Igor Korotabout 2 months ago4 messagesgeneral
Jump to latest
#1Igor Korot
ikorot01@gmail.com

Hi,

draft=# SELECT n.nspname, c.oid FROM pg_constraint c, pg_namespace n
WHERE c.oid = n.oid AND c.conname = 'leagues_pkey';
nspname | oid
---------+-----
(0 rows)

draft=# SELECT * FROM pg_constraint WHERE conname = 'leagues_pkey';
oid | conname | connamespace | contype | condeferrable |
condeferred | convalidated | conrelid | contypid | conindid |
conparentid | confrelid | confupdtype | confdeltype | confmatchtype |
conislocal | coninhcount | connoinherit | conkey | confkey | conpfeqop
| conppeqop | conffeqop | confdelsetcols | conexclop | conbin
-------+--------------+--------------+---------+---------------+-------------+--------------+----------+----------+----------+-------------+-----------+-------------+-------------+---------------+------------+-------------+--------------+--------+---------+-----------+-----------+-----------+----------------+-----------+--------
16395 | leagues_pkey | 2200 | p | f | f
| t | 16390 | 0 | 16394 | 0 |
0 | | | | t |
0 | t | {1} | | | |
| | |
(1 row)

Thank you.

#2Christoph Moench-Tegeder
cmt@burggraben.net
In reply to: Igor Korot (#1)
Re: Why there is no records?

## Igor Korot (ikorot01@gmail.com):

draft=# SELECT n.nspname, c.oid FROM pg_constraint c, pg_namespace n
WHERE c.oid = n.oid AND c.conname = 'leagues_pkey';

Because you're joining on the wrong column, see 3rd row of
https://www.postgresql.org/docs/current/catalog-pg-constraint.html

Regards,
Christoph

--
Spare Space

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Igor Korot (#1)
Re: Why there is no records?

On 2/16/26 15:59, Igor Korot wrote:

Hi,

draft=# SELECT n.nspname, c.oid FROM pg_constraint c, pg_namespace n
WHERE c.oid = n.oid AND c.conname = 'leagues_pkey';

Because you are doing:

c.oid = n.oid

which is comparing the pg_constraint.oid to the pg_namespace.oid which
are not the same thing.

You need:

c.connamespace = n.oid

nspname | oid
---------+-----
(0 rows)

draft=# SELECT * FROM pg_constraint WHERE conname = 'leagues_pkey';
oid | conname | connamespace | contype | condeferrable |
condeferred | convalidated | conrelid | contypid | conindid |
conparentid | confrelid | confupdtype | confdeltype | confmatchtype |
conislocal | coninhcount | connoinherit | conkey | confkey | conpfeqop
| conppeqop | conffeqop | confdelsetcols | conexclop | conbin
-------+--------------+--------------+---------+---------------+-------------+--------------+----------+----------+----------+-------------+-----------+-------------+-------------+---------------+------------+-------------+--------------+--------+---------+-----------+-----------+-----------+----------------+-----------+--------
16395 | leagues_pkey | 2200 | p | f | f
| t | 16390 | 0 | 16394 | 0 |
0 | | | | t |
0 | t | {1} | | | |
| | |
(1 row)

Thank you.

--
Adrian Klaver
adrian.klaver@aklaver.com

#4Igor Korot
ikorot01@gmail.com
In reply to: Adrian Klaver (#3)
Re: Why there is no records?

Thx.

Show quoted text

On Mon, Feb 16, 2026 at 6:03 PM Adrian Klaver <adrian.klaver@aklaver.com> wrote:

On 2/16/26 15:59, Igor Korot wrote:

Hi,

draft=# SELECT n.nspname, c.oid FROM pg_constraint c, pg_namespace n
WHERE c.oid = n.oid AND c.conname = 'leagues_pkey';

Because you are doing:

c.oid = n.oid

which is comparing the pg_constraint.oid to the pg_namespace.oid which
are not the same thing.

You need:

c.connamespace = n.oid

nspname | oid
---------+-----
(0 rows)

draft=# SELECT * FROM pg_constraint WHERE conname = 'leagues_pkey';
oid | conname | connamespace | contype | condeferrable |
condeferred | convalidated | conrelid | contypid | conindid |
conparentid | confrelid | confupdtype | confdeltype | confmatchtype |
conislocal | coninhcount | connoinherit | conkey | confkey | conpfeqop
| conppeqop | conffeqop | confdelsetcols | conexclop | conbin
-------+--------------+--------------+---------+---------------+-------------+--------------+----------+----------+----------+-------------+-----------+-------------+-------------+---------------+------------+-------------+--------------+--------+---------+-----------+-----------+-----------+----------------+-----------+--------
16395 | leagues_pkey | 2200 | p | f | f
| t | 16390 | 0 | 16394 | 0 |
0 | | | | t |
0 | t | {1} | | | |
| | |
(1 row)

Thank you.

--
Adrian Klaver
adrian.klaver@aklaver.com