Thread: \d doesn't show partitioned table foreign keys

\d doesn't show partitioned table foreign keys

From
Amit Langote
Date:
Hi.

I just noticed $subject, which attached seems to fix, although not sure if
that's the correct fix for the issue.

create table foo (a int primary key);
create table doo (a int primary key);
create table bar (a int references foo references doo) partition by list (a);
create table bar1 partition of bar for values in (1);

\d bar
                Table "public.bar"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           |          |
Partition key: LIST (a)
Number of partitions: 1 (Use \d+ to list them.)

But can see the key on the partition.

\d bar1
                Table "public.bar1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           |          |
Partition of: bar FOR VALUES IN (1)
Foreign-key constraints:
    "bar_a_fkey" FOREIGN KEY (a) REFERENCES foo(a)
    "bar_a_fkey1" FOREIGN KEY (a) REFERENCES doo(a)

After applying the patch:

\d bar
                Table "public.bar"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           |          |
Partition key: LIST (a)
Foreign-key constraints:
    "bar_a_fkey" FOREIGN KEY (a) REFERENCES foo(a)
    "bar_a_fkey1" FOREIGN KEY (a) REFERENCES doo(a)
Number of partitions: 1 (Use \d+ to list them.)

Will add this to open items.

Thanks,
Amit

Attachment

Re: \d doesn't show partitioned table foreign keys

From
Amit Langote
Date:
On 2018/05/14 11:50, Amit Langote wrote:
> Hi.
> 
> I just noticed $subject, which attached seems to fix, although not sure if
> that's the correct fix for the issue.

I updated the comment above the changed code to explain things as I see them.

Attached updated patch.

Thanks,
Amit

Attachment

Re: \d doesn't show partitioned table foreign keys

From
Alvaro Herrera
Date:
On 2018-May-14, Amit Langote wrote:

> Hi.
> 
> I just noticed $subject, which attached seems to fix, although not sure if
> that's the correct fix for the issue.

The fix looks good to me.  Will push shortly.

A related issue is that \d of the referenced table shows both the
partitioned table as well as all of its partitions, which seems too
repetitive.  I think we should only list the partitioned table itself.
Thoughts?

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: \d doesn't show partitioned table foreign keys

From
Amit Langote
Date:
On Tue, May 15, 2018 at 12:38 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> On 2018-May-14, Amit Langote wrote:
>
>> Hi.
>>
>> I just noticed $subject, which attached seems to fix, although not sure if
>> that's the correct fix for the issue.
>
> The fix looks good to me.  Will push shortly.

Thank you.

> A related issue is that \d of the referenced table shows both the
> partitioned table as well as all of its partitions, which seems too
> repetitive.  I think we should only list the partitioned table itself.
> Thoughts?

Yeah, I think showing only the partitioned table makes sense, assuming
that the triggers and constraint entries on the partitions are an
implementation detail.  Right?

Thanks,
Amit