Re: r there downsides to explicitly naming a pk column xxxx_pk - Mailing list pgsql-novice

From David G. Johnston
Subject Re: r there downsides to explicitly naming a pk column xxxx_pk
Date
Msg-id CAKFQuwbiZgU527QMKB0GgdfaVLmpN39RkPUzsgw-dd7gFS2f8Q@mail.gmail.com
Whole thread Raw
In response to Re: r there downsides to explicitly naming a pk column xxxx_pk  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
List pgsql-novice
On Thu, Dec 14, 2017 at 1:41 PM, Gavin Flower <GavinFlower@archidevsys.co.nz> wrote:
Since we know the current table name, it is redundant to name the table's primary key with the its table name.

​Redundant but useful - I am a huge proponent of USING clauses in joins:

pk_tbl JOIN fk_tbl USING (pk_tbl_id)

As for "finding the PK" - its almost always the first column in the table​, ends in "id", and has a reasonable prefix.

Being able to "grep pk_tbl_id" is also nice in many cases.  Grepping "id" provides no useful value - though if one always uses table prefixes then grepping "pk_tbl.id" would mitigate that particular problem.

David J.

pgsql-novice by date:

Previous
From: Gavin Flower
Date:
Subject: Re: r there downsides to explicitly naming a pk column xxxx_pk
Next
From: Greg Robson
Date:
Subject: Re: r there downsides to explicitly naming a pk column xxxx_pk