Re: Does included columns part of the PK - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Does included columns part of the PK
Date
Msg-id da939085-813e-4505-880d-aafa91c8509d@aklaver.com
Whole thread Raw
In response to Re: Does included columns part of the PK  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Does included columns part of the PK
List pgsql-general
On 3/16/26 2:30 PM, Adrian Klaver wrote:
> On 3/16/26 11:47 AM, Igor Korot wrote:
> 
> Reply to list also.
> Ccing list.
>> Adrian,
>>
>>
>>
>> On Mon, Mar 16, 2026, 8:03 AM Adrian Klaver <adrian.klaver@aklaver.com 
>> <mailto:adrian.klaver@aklaver.com>> wrote:
>>
>>     On 3/15/26 6:23 PM, Igor Korot wrote:
>>      > Hi, Adrian,
>>      >
>>      > Here is the log file from running in ODBC mode: https://bpa.st/
>>     Z2DWG <https://bpa.st/Z2DWG>
>>
>>     I have no idea what this is trying to show?
>>
>>
>> The log shows ODBC connection and then at the end - call to 
>> SQLPrimaryKeys().
> 
> Where?
> 
> I don't see that in either the link you posted or the text file Greg 
> sent to the list.
> 
>>
>> If you run it against the table I posted above, you will get 3 fields. 
>> Whereas it should be just one.
> 
> Again, run it how?

Alright I see what you are talking about now. I'm not using the ODBC 
driver just it's query. In psql :

CREATE TABLE leagues_new (
     id serial,
     name varchar(100),
     drafttype smallint,
     scoringtype smallint,
     roundvalues smallint,
     leaguetype char(5),
     salary integer,
     benchplayers smallint,
     PRIMARY KEY (id) INCLUDE (drafttype, scoringtype
) WITH (fillfactor = 50, deduplicate_items = OFF)
);


SELECT
     ta.attname,
     ia.attnum,
     ic.relname,
     n.nspname,
     tc.relname
FROM
     pg_catalog.pg_attribute ta,
     pg_catalog.pg_attribute ia,
     pg_catalog.pg_class tc,
     pg_catalog.pg_index i,
     pg_catalog.pg_namespace n,
     pg_catalog.pg_class ic
WHERE
     tc.relname = 'leagues_new'
     AND n.nspname = 'public'
     AND tc.oid = i.indrelid
     AND n.oid = tc.relnamespace
     AND i.indisprimary = 't'
     AND ia.attrelid = i.indexrelid
     AND ta.attrelid = i.indrelid
     AND ta.attnum = i.indkey[ia.attnum - 1]
     AND (NOT ta.attisdropped)
     AND (NOT ia.attisdropped)
     AND ic.oid = i.indexrelid
ORDER BY
     ia.attnum;

yields

attname   | attnum |     relname      | nspname |   relname
-------------+--------+------------------+---------+-------------
  id          |      1 | leagues_new_pkey | public  | leagues_new
  drafttype   |      2 | leagues_new_pkey | public  | leagues_new
  scoringtype |      3 | leagues_new_pkey | public  | leagues_new


> 
>>
>> Thank you.
>>


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Does included columns part of the PK
Next
From: Igor Korot
Date:
Subject: Re: Does included columns part of the PK