pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix hard-coded relkind constants in pg_dump.c.
7+ messages / 2 participants
[nested] [flat]

* pgsql: Fix hard-coded relkind constants in pg_dump.c.
@ 2017-03-10 00:19 Tom Lane <tgl@sss.pgh.pa.us>
  2017-03-10 00:46 ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2017-03-10 00:19 UTC (permalink / raw)
  To: pgsql-committers

Fix hard-coded relkind constants in pg_dump.c.

Although it's reasonable to expect that most of these constants will
never change, that does not make it good programming style to hard-code
the value rather than using the RELKIND_FOO macros.  There were only
a few such violations, and all relatively new AFAICT.

Existing style is mostly to inject relkind values into constructed
query strings using %c.  I did not bother to touch places that did it
like that, but really a better technique is to stringify the RELKIND
macro, at least in places where you'd want single quotes around the
code character.  That avoids any runtime effort and keeps the RELKIND
symbol close to where it's used.

Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fe797b4a6a69ec0c9bf6ff992eac20c4084fda41

Modified Files
--------------
src/bin/pg_dump/pg_dump.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c.
  2017-03-10 00:19 pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
@ 2017-03-10 00:46 ` Michael Paquier <michael.paquier@gmail.com>
  2017-03-10 01:59   ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Paquier @ 2017-03-10 00:46 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>

On Fri, Mar 10, 2017 at 9:19 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Fix hard-coded relkind constants in pg_dump.c.
>
> Although it's reasonable to expect that most of these constants will
> never change, that does not make it good programming style to hard-code
> the value rather than using the RELKIND_FOO macros.  There were only
> a few such violations, and all relatively new AFAICT.
>
> Existing style is mostly to inject relkind values into constructed
> query strings using %c.  I did not bother to touch places that did it
> like that, but really a better technique is to stringify the RELKIND
> macro, at least in places where you'd want single quotes around the
> code character.  That avoids any runtime effort and keeps the RELKIND
> symbol close to where it's used.

I have been wondering about the lack of readability with those
hardcoded relkinds in the code for some time but... Wouldn't it be
better to change as well psql's describe.c and tab_complete.c, as well
as pg_upgrade and initdb code?
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c.
  2017-03-10 00:19 pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
  2017-03-10 00:46 ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Michael Paquier <michael.paquier@gmail.com>
@ 2017-03-10 01:59   ` Tom Lane <tgl@sss.pgh.pa.us>
  2017-03-10 02:18     ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2017-03-10 01:59 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>

Michael Paquier <michael.paquier@gmail.com> writes:
> On Fri, Mar 10, 2017 at 9:19 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Existing style is mostly to inject relkind values into constructed
>> query strings using %c.  I did not bother to touch places that did it
>> like that, but really a better technique is to stringify the RELKIND
>> macro, at least in places where you'd want single quotes around the
>> code character.  That avoids any runtime effort and keeps the RELKIND
>> symbol close to where it's used.

> I have been wondering about the lack of readability with those
> hardcoded relkinds in the code for some time but... Wouldn't it be
> better to change as well psql's describe.c and tab_complete.c, as well
> as pg_upgrade and initdb code?

Yup, working on it.

There's a fair number of other fields that could stand the same treatment,
but for now I'm just going to touch references to relkind.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c.
  2017-03-10 00:19 pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
  2017-03-10 00:46 ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Michael Paquier <michael.paquier@gmail.com>
  2017-03-10 01:59   ` Re: [COMMITTERS] pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
@ 2017-03-10 02:18     ` Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Michael Paquier @ 2017-03-10 02:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>

On Fri, Mar 10, 2017 at 10:59 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Michael Paquier <michael.paquier@gmail.com> writes:
>> On Fri, Mar 10, 2017 at 9:19 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> Existing style is mostly to inject relkind values into constructed
>>> query strings using %c.  I did not bother to touch places that did it
>>> like that, but really a better technique is to stringify the RELKIND
>>> macro, at least in places where you'd want single quotes around the
>>> code character.  That avoids any runtime effort and keeps the RELKIND
>>> symbol close to where it's used.
>
>> I have been wondering about the lack of readability with those
>> hardcoded relkinds in the code for some time but... Wouldn't it be
>> better to change as well psql's describe.c and tab_complete.c, as well
>> as pg_upgrade and initdb code?
>
> Yup, working on it.
>
> There's a fair number of other fields that could stand the same treatment,
> but for now I'm just going to touch references to relkind.

Yes, I just noticed postgres_fdw as well...
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix hard-coded relkind constants in psql/describe.c.
@ 2017-03-10 01:46 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2017-03-10 01:46 UTC (permalink / raw)
  To: pgsql-committers

Fix hard-coded relkind constants in psql/describe.c.

Although it's reasonable to expect that most of these constants will
never change, that does not make it good programming style to hard-code
the value rather than using the RELKIND_FOO macros.

Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/395bfaae8e786eb17fc9dd79e4636f97c9d9b820

Modified Files
--------------
src/bin/psql/describe.c | 203 ++++++++++++++++++++++++++++--------------------
1 file changed, 120 insertions(+), 83 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix hard-coded relkind constants in assorted src/bin files.
@ 2017-03-10 03:45 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2017-03-10 03:45 UTC (permalink / raw)
  To: pgsql-committers

Fix hard-coded relkind constants in assorted src/bin files.

Although it's reasonable to expect that most of these constants will
never change, that does not make it good programming style to hard-code
the value rather than using the RELKIND_FOO macros.

Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fcd778eb703c154c0fbba249e17c21b7ae4de19b

Modified Files
--------------
src/bin/initdb/initdb.c         | 17 ++++++++++++----
src/bin/pg_dump/pg_dump_sort.c  | 14 +++++++------
src/bin/pg_upgrade/info.c       |  4 +++-
src/bin/pg_upgrade/pg_upgrade.c | 11 ++++++++--
src/bin/pg_upgrade/version.c    |  7 ++++++-
src/bin/psql/command.c          |  5 +++--
src/bin/psql/tab-complete.c     | 45 ++++++++++++++++++++++++++++-------------
src/bin/scripts/vacuumdb.c      | 10 +++++++--
8 files changed, 81 insertions(+), 32 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix hard-coded relkind constants in assorted other files.
@ 2017-03-10 04:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2017-03-10 04:37 UTC (permalink / raw)
  To: pgsql-committers

Fix hard-coded relkind constants in assorted other files.

Although it's reasonable to expect that most of these constants will
never change, that does not make it good programming style to hard-code
the value rather than using the RELKIND_FOO macros.

I think I've now gotten all the hard-coded references in C code.
Unfortunately there's no equally convenient way to parameterize
SQL files ...

Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9c2635e26f6f4e34b3b606c0fc79d0e111953a74

Modified Files
--------------
contrib/oid2name/oid2name.c           | 17 ++++++++++++-----
contrib/postgres_fdw/postgres_fdw.c   |  7 ++++++-
contrib/vacuumlo/vacuumlo.c           |  4 +++-
src/backend/utils/adt/xml.c           | 17 +++++++++++++++--
src/tools/findoidjoins/findoidjoins.c | 20 ++++++++++++--------
5 files changed, 48 insertions(+), 17 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2017-03-10 04:37 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 00:19 pgsql: Fix hard-coded relkind constants in pg_dump.c. Tom Lane <tgl@sss.pgh.pa.us>
2017-03-10 00:46 ` Michael Paquier <michael.paquier@gmail.com>
2017-03-10 01:59   ` Tom Lane <tgl@sss.pgh.pa.us>
2017-03-10 02:18     ` Michael Paquier <michael.paquier@gmail.com>
2017-03-10 01:46 pgsql: Fix hard-coded relkind constants in psql/describe.c. Tom Lane <tgl@sss.pgh.pa.us>
2017-03-10 03:45 pgsql: Fix hard-coded relkind constants in assorted src/bin files. Tom Lane <tgl@sss.pgh.pa.us>
2017-03-10 04:37 pgsql: Fix hard-coded relkind constants in assorted other files. Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox