Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vw0Xi-00F9wY-11 for pgsql-general@arkaria.postgresql.org; Fri, 27 Feb 2026 16:18:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vw0Xh-004jEH-0d for pgsql-general@arkaria.postgresql.org; Fri, 27 Feb 2026 16:18:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vw0Xg-004jDz-2N for pgsql-general@lists.postgresql.org; Fri, 27 Feb 2026 16:18:16 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vw0Xd-00000001Wb8-37l6 for pgsql-general@lists.postgresql.org; Fri, 27 Feb 2026 16:18:15 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7d4c383f2fcso416335a34.0 for ; Fri, 27 Feb 2026 08:18:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772209094; cv=none; d=google.com; s=arc-20240605; b=JCDBjWd5UNKThbwXvlcLQOhFaQ2K8Pr1cuPfGuHA1D4SbBA3OGXCqkDiIsELwIb/Y8 NHPKo9q+AHmUpfX4u2edwsaNZlbYnpJg4OHn9Q5KszepQOzmmOBpX7CBR+VDxAWIYIfo LBrSAMVfd7zL7lGUwU0aoKfeeXy7lqqpfhrADFYA084q9uy2fHRJfGRAcOi7geh0t5rq s14N2TtAd1dleSYokbJkjHgiNUf11p+eaQujPZ/aWhNM1M3CjxpRnTOFe/QY9FQhGgyg UzJlcUalBS/YB9vmb8p9zP17OXCZQ7gcBqGii8e2NnMzhOXNBb97dyZa+K+fxA2nS/1m w/PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=lpm+ITJNp9TDT2bGHYp3T8algTmYdo6yR1xLjlZg5Lk=; fh=MqX3/PjeIRWyveucHIwmT3MEzIvphFWgoM5FEnVDTkI=; b=bVMLV4yh+Dhjcv69G3PX5SdOJFa9yEZ/NJ117Gi0HkYQUkgbWHbQUgdGNkX08cL95c CkvARQluD57tUDdqEK34Y75XiunfkqkreCQuCnDtramFKMYJWXnI/cN+WLwvM2i2eqnL FiKMRskosXpk8JFbVIjqEJSIjhRuW02WFjlglzYL7nap2UOPSZwmQ05uRJB9KnQSND5o RLD/xRb1hCWauYcZeTABuLk3DBtyZPjEWMAHjaXgOVPfdZlmc0Qm8SvQgpqqdv5hkRyQ hHQ2xBvWnGx4JWFBhoFRpcHaP/ZOuuDzFYmjU9dOt4FOCF+X1EOx53701wPeusK2Iuf5 jlNQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772209094; x=1772813894; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lpm+ITJNp9TDT2bGHYp3T8algTmYdo6yR1xLjlZg5Lk=; b=FwraobX/tzwwboyJlGdGzUQwZDzcB969C90jzf4w44d12kbwecgFirIQJq2G9y+WhN E7Jp+y2X5uPzPrMZnbdX2t7p0K+/l/NHD8Yv5wz+zS6sulcZneF/I2ejdejJEIsmxWZq vj4M+0BBio4MwD8an8Ole6853z6WSpi+UDanRJ5Omm5RhhKk+608cDVyIPl8uLlO+Jdk 9F99no3omUK101Di6xDkuhmAPGiKuwULVhM5e+lIxCdTz57K0sySLE3ajmPjf1laeMqE 4bC4+TKGVjRd7c2ATu5ZZKZsjAqGMkNmgTElj6QwdLHN1RNp56ngfDWNk7y1rhj84y+D uBkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772209094; x=1772813894; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lpm+ITJNp9TDT2bGHYp3T8algTmYdo6yR1xLjlZg5Lk=; b=JrP9KgL2YS6SlpiLixvvawm998eGeEeBVTE9Bn25itKyj/j5IanWhpy4DqOQGVuBwg Ch8EYJzMX9700V/L/alY304HjF+2uv7vNPhCHK6l6CPYEGGFdnIkcsDnF0iZy9LTrfpI FyD9SNAMyJuHnBHSXT1huHSmfkE500MmZgJF2iFkufod94KpMS3a7RZ45Qq9YcB6drdz KEWJ0U1SdQFIT59sjvJGEhkdAG96dg71f0Fm7DpFLZNR6M8V2IllpsH2u6+L3mHfM2Ln 6J0qo0kaMNRsy+wD2xFOw6dngKRhG/y8b/BEW9m/gEa7a6JRBMJCcHpKNju1/9EPveXn 4NGw== X-Gm-Message-State: AOJu0YyYrHaMtiOGIJJA1MkKLYHIuEAKskN/iF+JZkdwaA+jcjJPJA9/ fiNMBHDEXVuvwA3Co/5KXlIulu6iAX15wCEFBAGypANzLYuGKlgYuJqq6payurpKdS6f8f3aWjX EigZ3QfVsobLfpm09EjHMjpNq0kWLplw= X-Gm-Gg: ATEYQzzSHX1DenKCaIuIMoCHLDo5n1qNsOe3kRRqXViIOzl0ZkLpTorVhJW+jyCGxVO +eYhEn8pWoh18doR3Ovjca0FHQlqNGk+tbP+r9w4rzQabDLzfe2fGbYszAEaLzjktSo6xLK+4EV vHJPe2dSf1TW1EuQXQfMn7aIL0e4jN6KMKXAWwyD3D1hh97nZPKy/DbAF7/pYngGE1sx4czsgfu xhV6ws51K59u8k2A+wmCsJKxolySD/PeoIDmuhxRGH0uU0VWVpuMKgXZ4fMZ1x9Ht371A/HNE0k 9Esxo/w= X-Received: by 2002:a05:6820:81d2:b0:676:bfb4:d239 with SMTP id 006d021491bc7-679fae1705fmr1957084eaf.22.1772209094098; Fri, 27 Feb 2026 08:18:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Fri, 27 Feb 2026 09:17:38 -0700 X-Gm-Features: AaiRm53n1vW3Bv1QgrRxqzGICO8-fC32-bf5ZCR3nG85s8BxWp9f3tockdpsBvA Message-ID: Subject: Re: Where the info is stored To: Igor Korot Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000008583fe064bd09567" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008583fe064bd09567 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Please keep replies on-list. On Mon, Feb 16, 2026 at 5:49=E2=80=AFPM David G. Johnston < david.g.johnston@gmail.com> wrote: > On Monday, February 16, 2026, Igor Korot wrote: > >> >> Where are included columns > > >> > pg_attribute, though you need info from pg_index to interpret the content= s. > Specifically: \set ON_ERROR_STOP on BEGIN; CREATE TABLE wip_idx_include_demo ( id integer NOT NULL, secondary_id integer NOT NULL, included_payload text, notes text, CONSTRAINT wip_idx_include_demo_id_secondary_uq UNIQUE (id, secondary_id) INCLUDE (included_payload) ); WITH idx AS ( SELECT i.indexrelid, i.indrelid, i.indnkeyatts, i.indkey::int2[] AS indkey FROM pg_index i JOIN pg_class ic ON ic.oid =3D i.indexrelid JOIN pg_namespace ns ON ns.oid =3D ic.relnamespace WHERE ns.nspname =3D 'public' AND ic.relname =3D 'wip_idx_include_demo_id_secondary_uq' ), ords AS ( SELECT idx.indexrelid, idx.indrelid, idx.indnkeyatts, s.ord, idx.indkey[s.ord] AS attnum FROM idx CROSS JOIN LATERAL generate_subscripts(idx.indkey, 1) AS s(ord) ) SELECT ns.nspname AS schema_name, ic.relname AS index_name, tc.relname AS table_name, a.attname AS column_name, CASE WHEN ords.ord < ords.indnkeyatts THEN 'key' ELSE 'include' END AS column_role, ords.ord + 1 AS index_position FROM ords JOIN pg_class ic ON ic.oid =3D ords.indexrelid JOIN pg_namespace ns ON ns.oid =3D ic.relnamespace JOIN pg_class tc ON tc.oid =3D ords.indrelid JOIN pg_attribute a ON a.attrelid =3D ords.indrelid AND a.attnum =3D ords.attnum AND NOT a.attisdropped ORDER BY ords.ord \gx \d+ wip_idx_include_demo_id_secondary_uq --given that the above provides the relevant info Greg's suggestion would also get you a functioning base query. ROLLBACK; David J. --0000000000008583fe064bd09567 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Please keep replies on-list.

<= span style=3D"font-family:Arial,Helvetica,sans-serif">On Mon, Feb 16, 2026 = at 5:49=E2=80=AFPM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Monday, February 16, 2026, Igor Korot <ikorot01@gmail.com>= wrote:

Where are included columns=C2=A0

=C2=A0
pg_attribute, th= ough you need info from pg_index to interpret the contents.

Specifically:

\set ON_ERROR_STOP= on

BEGIN;

CREATE TABLE wip_idx_include_demo (
=C2=A0 =C2= =A0 id integer NOT NULL,
=C2=A0 =C2=A0 secondary_id integer NOT NULL,=C2=A0 =C2=A0 included_payload text,
=C2=A0 =C2=A0 notes text,
=C2= =A0 =C2=A0 CONSTRAINT wip_idx_include_demo_id_secondary_uq
=C2=A0 =C2=A0= =C2=A0 =C2=A0 UNIQUE (id, secondary_id) INCLUDE (included_payload)
);
WITH idx AS (
=C2=A0 =C2=A0 SELECT i.indexrelid, i.indrelid, i.ind= nkeyatts, i.indkey::int2[] AS indkey
=C2=A0 =C2=A0 FROM pg_index i
= =C2=A0 =C2=A0 JOIN pg_class ic ON ic.oid =3D i.indexrelid
=C2=A0 =C2=A0 = JOIN pg_namespace ns ON ns.oid =3D ic.relnamespace
=C2=A0 =C2=A0 WHERE n= s.nspname =3D 'public'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= AND ic.relname =3D 'wip_idx_include_demo_id_secondary_uq'
), or= ds AS (
=C2=A0 =C2=A0 SELECT idx.indexrelid,
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0idx.indrelid,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= idx.indnkeyatts,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s.ord,
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0idx.indkey[s.ord] AS attnum
=C2=A0= =C2=A0 FROM idx
=C2=A0 =C2=A0 CROSS JOIN LATERAL generate_subscripts(id= x.indkey, 1) AS s(ord)
)
SELECT ns.nspname AS schema_name,
=C2=A0 = =C2=A0 =C2=A0 =C2=A0ic.relname AS index_name,
=C2=A0 =C2=A0 =C2=A0 =C2= =A0tc.relname AS table_name,
=C2=A0 =C2=A0 =C2=A0 =C2=A0a.attname AS col= umn_name,
=C2=A0 =C2=A0 CASE WHEN ords.ord < ords.indnkeyatts THEN &#= 39;key' ELSE 'include' END AS column_role,
=C2=A0 =C2=A0 ord= s.ord + 1 AS index_position
FROM ords
JOIN pg_class ic ON ic.oid =3D = ords.indexrelid
JOIN pg_namespace ns ON ns.oid =3D ic.relnamespace
JO= IN pg_class tc ON tc.oid =3D ords.indrelid
JOIN pg_attribute a ON a.attr= elid =3D ords.indrelid
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0AND a.attnum =3D ords.attnum
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0AND NOT a.attisdropped
O= RDER BY ords.ord \gx

\d+ wip_idx_include_demo_id_secondary_uq
<= div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif= ">--given that the above provides the relevant info Greg's suggestion w= ould also get you a functioning base query.

ROLLBACK;
=

David J.

--0000000000008583fe064bd09567--