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 1wyPxx-003NBd-0J for pgsql-general@arkaria.postgresql.org; Mon, 24 Aug 2026 08:23:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wyPxv-001LA6-2I for pgsql-general@arkaria.postgresql.org; Mon, 24 Aug 2026 08:23:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wyPxv-001L9w-0l for pgsql-general@lists.postgresql.org; Mon, 24 Aug 2026 08:23:35 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wyPxs-00000000yPa-3Qg0 for pgsql-general@lists.postgresql.org; Mon, 24 Aug 2026 08:23:34 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-480001972b8so720205f8f.2 for ; Mon, 24 Aug 2026 01:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787559810; x=1788164610; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=P7QJ96RD9gmfQnhHsclsoaPpSCzHFXQ9HUxdGM+0RUI=; b=XQj0sIYMVW1hYm58aWw8PIYoAHhSg57QM9foaJtRwl5ohZn9Rl5qPrznOVeOqTv85J cc9pa3Bpk14vBDneTnt1PVvQDbnvchHeCsmtTWM87Oi71hRuvx9B+grm6FAnm3SDPZCH mo8fwfCBfeDXCMY12xwx4OsmYPydbxLMyjKEZ/4PfKesBWaTw1jBuWeN1dWzzEUOZn0G HN7rKHrxolGUz+Txqa+o1vVVwjgGkaKDMc4GGXU0/uP6FILNhLgsVdmeBdsOGu3s31v8 v92ctiZpuxXjVYfqd1B76YB3QuJKPc6W3uavq/9e7dKO4uu3Y4Dfidi/T8DgDZxOZ1C/ N0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787559810; x=1788164610; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P7QJ96RD9gmfQnhHsclsoaPpSCzHFXQ9HUxdGM+0RUI=; b=JrHzh3bZfxEiBwPyGDJywzHvxjLxHO/ta+pAsT3z/wFUbZH6LsegcuyT6R+81awpBo rEJ2yJ2MXJAG188McHVx4He6k4pNZht6n8zdr4T3OxcCr8XYef/Pal449OXEHBqQ0v4e zV0ZS+Bu59s9tCrVWfStDcX6h97fVQAua9WgecI5XnQNfIFLun1jaT/KuLzlIH14Uqwe oL0viP14DpJNUKzAAXfGrrX4DdV/PC1KVP9OQWJnUR5brtyQYpIPFhsWxpqDN87b6fGn llgaMy731Ql1tvPriLTcu7M8S+dLnQqCYvzqae/I87LvXz9BoEY29L6AwWhQ949F5tnU pTTA== X-Forwarded-Encrypted: i=1; AHgh+RpTXuXEzAT22D4lvQINxq8wJGkdDjswP7Ch9xxHN67mwW8VT8AGhQCa+DuGphr+5vDgJK0Nf0MoSRe++viJ@lists.postgresql.org X-Gm-Message-State: AFuF++k4lFsqIUtVFjfrSO2lZQczJMHEzX2cJQM3xbsQ3xV3cLG1ygqk 0m1FgYWNeP0PR1Fr2CepgNnqQjnRWFk5j/xpunc2+0WJ/HkEihB+PR3X X-Gm-Gg: AR+sD11jcYOMk+PKKk64tdtm8899p7SgAzz1YPpSV1gMJc4vmRXNpxaQGj59VB6ild6 3fUc0VUEzuqbSViXGk0iUSUyjvDy33r2Ogs6FkdQr8rRg0Y1Wulc5daOcsyA5w/oCYIKot1/5ih /YBAK8HYgRMw0J/kcxwVHWOtBe+LwOkru6PUxHdYDlzYuTO9OfM6eeyydrmYVBMCkTz6U/VVlRb tg9VRdgp+u/DKu+kmifwjgofuY02+47KTt282ote+1VxZZYGxeJjcZ4DoZhCEkAiy6f/sZDc+fB XecTWFvyhnODtlV03m4hr4B2iI4ze3SGjE9bhyvSlUIdqZfldybn3niosbbETkN1HAlCkhyiW8u 2HblFzc1v3dxJnuy11RLrj0wayt4RdPwrDLVTponb54iwz6XINzw4YFZYMz3XZd/Rv/omL28MxY eIFRNA95RFa1gr+hhsFGbHTexuw04d0gwsNJ97wK0xi4w6E71VsPZVCYj+4zG7fgm3OKg7+AWnx KZL6dlUBQoIys4g2LUDQemB5EYpHik4mPpLBCcF3g== X-Received: by 2002:a05:6000:4543:b0:482:c5ee:c7a9 with SMTP id ffacd0b85a97d-482c5eece65mr18126202f8f.17.1787559809700; Mon, 24 Aug 2026 01:23:29 -0700 (PDT) Received: from ?IPV6:2a01:e0a:bf8:b480:af85:2172:7dcd:75e0? ([2a01:e0a:bf8:b480:af85:2172:7dcd:75e0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482c9b78e07sm7305040f8f.9.2026.08.24.01.23.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Aug 2026 01:23:29 -0700 (PDT) Message-ID: <313a3a99-0131-49d5-a372-cc1dfbe7bb69@gmail.com> Date: Mon, 24 Aug 2026 10:23:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: information_schema.constraint_column_usage view missing info To: Xavier Tarifa , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Pierre Forstmann In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello; Try using INFORMATION_SCHEMA.KEY_COLUMN_USAGE: CREATE SCHEMA create table proves.test (suc_pk int primary key); CREATE TABLE create table proves.test1 (suc_fk integer); CREATE TABLE create table proves.test2 (suc_fk integer); CREATE TABLE alter table proves.test1 add constraint fk1 foreign key (suc_fk) references proves.test; ALTER TABLE alter table proves.test2 add constraint fk1 foreign key (suc_fk) references proves.test; ALTER TABLE select * from information_schema.constraint_column_usage where constraint_name = 'fk1';  table_catalog | table_schema | table_name | column_name | constraint_catalog | constraint_schema | constraint_name ---------------+--------------+------------+-------------+--------------------+-------------------+-----------------  pierre        | proves       | test       | suc_pk      | pierre             | proves            | fk1  pierre        | proves       | test       | suc_pk      | pierre             | proves            | fk1 (2 rows) select * from information_schema.key_column_usage where constraint_name = 'fk1';  constraint_catalog | constraint_schema | constraint_name | table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint --------------------+-------------------+-----------------+---------------+--------------+------------+-------------+------------------+-------------------------------  pierre             | proves            | fk1             | pierre        | proves       | test1      | suc_fk      |         1 |                             1  pierre             | proves            | fk1             | pierre        | proves       | test2      | suc_fk      |         1 |                             1 (2 rows) Le 24/08/2026 à 08:44, Xavier Tarifa a écrit : > Hello community, > how do you go about finding information about constraint columns? I > was trying to use the view information_schema.constraint_column_usage > but I've found out that to uniquely identify a constraint it would > need to show the constraint table, but in case of foreign keys it only > shows the table of the referenced column. > For example: > > create schema proves; > > create table proves.test (suc_pk int primary key); > > create table proves.test1 (suc_fk integer); > > create table proves.test2 (suc_fk integer); > > alter table proves.test1 add constraint fk1 foreign key (suc_fk) > references proves.test; > > alter table proves.test2 add constraint fk1 foreign key (suc_fk) > references proves.test; > > then when I try to read the constraint the columns reference I can't > know distinguish the constraint on test1 from the constraint on test2: > > select * from information_schema.constraint_column_usage > where constraint_name = 'fk1'; > > I guess I could look at the view definition and add use the same query > but adding the table constraint, but I don't know if these view > definitions might change with new postgres versions or not, I would > like something that I don't have to worry that it might stop working > in the future. > How would you go about it? > >