| From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
|---|---|
| To: | Igor Korot <ikorot01(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Does included columns part of the PK |
| Date: | 2026-03-14 23:30:19 |
| Message-ID: | 3547f40b-08b9-4d0c-bba8-f1c26d0bf09d@aklaver.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general pgsql-odbc |
On 3/14/26 9:56 AM, Igor Korot wrote:
> Hi,
>
> On Sat, Mar 14, 2026 at 8:51 AM David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com <mailto:david(dot)g(dot)johnston(at)gmail(dot)com>> wrote:
>
> On Saturday, March 14, 2026, Adrian Klaver
> <adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
> On 3/14/26 12:09 AM, Igor Korot wrote:
>
> Hi, ALL,
> Have one weird question ;-)
>
> When I connect with ODBC and call SQLPrimaryKey() the
> function returns
>
>
> Are you actually using the SQLPrimaryKeys(), not SQLPrimaryKey()?
>
> all fields including
> "included" fields.
>
>
> Define 'included' fields.
>
>
> They are referring to the unique index that backs the PK constraint.
>
>
> Not “they” - “He”. 😊
>
> And yes - that’s what I’m referring to.
From here:
1 TABLE_CAT VARCHAR(128) This is always null.
2 TABLE_SCHEM VARCHAR(128) The name of the schema containing TABLE_NAME.
3 TABLE_NAME VARCHAR(128) NOT NULL Name of the specified table.
4 COLUMN_NAME VARCHAR(128) NOT NULL Primary key column name.
5 KEY_SEQ SMALLINT NOT NULL Column sequence number in the primary key,
starting with 1.
6 PK_NAME VARCHAR(128) Primary key identifier. Contains a null value if
not applicable to the data
From here:
https://github.com/postgresql-interfaces/psqlodbc/blob/main/info.c
At line 4035 in SQLPrimaryKeys()
For case 1
/*
* Simplified query to remove assumptions about number of
* possible index columns. Courtesy of Tom Lane - thomas
* 2000-03-21
*/
[...]
"select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname"
" from pg_catalog.pg_attribute ta ... "
case 2
select ta.attname, ia.attnum, ic.relname, n.nspname, NULL"
" from pg_catalog.pg_attribute ta, ..."
If I am following correctly then:
attname = column_name
attnum = key_seq
ic.relname = pk_name
nspname = table_schem
tc.relname = table_name
So how are using it in your code and what are the actual results?
Also what is showing up in the Postgres logs?
>
> Thank you.
>
>
> David J.
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Igor Korot | 2026-03-15 06:24:38 | Re: Does included columns part of the PK |
| Previous Message | Igor Korot | 2026-03-14 16:56:55 | Re: Does included columns part of the PK |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Igor Korot | 2026-03-15 06:24:38 | Re: Does included columns part of the PK |
| Previous Message | Igor Korot | 2026-03-14 16:56:55 | Re: Does included columns part of the PK |