pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: remove extra space from dumped ALTER DEFAULT PRIVILEGES commands
Date: Tue, 6 Dec 2022 15:27:44 -0800
Message-ID: <20221206232744.GA3560301@nathanxps13> (raw)

Hi hackers,

pg_dump adds an extra space in ALTER DEFAULT PRIVILEGES commands.  AFAICT
it's been this way since the command was first introduced (249724c).  I've
attached a patch to fix it.

This is admittedly just a pet peeve, but maybe it is bothering others, too.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachments:

remove_extra_space.patch (text/x-diff, 3.4K) download diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 9311417f18..694a28f532 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -184,7 +184,9 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, prefix, privs->data, type); if (nspname && *nspname) appendPQExpBuffer(firstsql, "%s.", fmtId(nspname)); - appendPQExpBuffer(firstsql, "%s FROM ", name); + if (name && *name) + appendPQExpBuffer(firstsql, "%s ", name); + appendPQExpBufferStr(firstsql, "FROM "); if (grantee->len == 0) appendPQExpBufferStr(firstsql, "PUBLIC;\n"); else @@ -253,7 +255,9 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, prefix, privs->data, type); if (nspname && *nspname) appendPQExpBuffer(thissql, "%s.", fmtId(nspname)); - appendPQExpBuffer(thissql, "%s TO ", name); + if (name && *name) + appendPQExpBuffer(thissql, "%s ", name); + appendPQExpBufferStr(thissql, "TO "); if (grantee->len == 0) appendPQExpBufferStr(thissql, "PUBLIC;\n"); else @@ -265,7 +269,9 @@ buildACLCommands(const char *name, const char *subname, const char *nspname, prefix, privswgo->data, type); if (nspname && *nspname) appendPQExpBuffer(thissql, "%s.", fmtId(nspname)); - appendPQExpBuffer(thissql, "%s TO ", name); + if (name && *name) + appendPQExpBuffer(thissql, "%s ", name); + appendPQExpBufferStr(thissql, "TO "); if (grantee->len == 0) appendPQExpBufferStr(thissql, "PUBLIC"); else diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 6656222363..4732ee2e4a 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -563,7 +563,7 @@ my %tests = ( regexp => qr/^ \QALTER DEFAULT PRIVILEGES \E \QFOR ROLE regress_dump_test_role IN SCHEMA dump_test \E - \QGRANT SELECT ON TABLES TO regress_dump_test_role;\E + \QGRANT SELECT ON TABLES TO regress_dump_test_role;\E /xm, like => { %full_runs, %dump_test_schema_runs, section_post_data => 1, }, @@ -582,7 +582,7 @@ my %tests = ( regexp => qr/^ \QALTER DEFAULT PRIVILEGES \E \QFOR ROLE regress_dump_test_role IN SCHEMA dump_test \E - \QGRANT ALL ON FUNCTIONS TO regress_dump_test_role;\E + \QGRANT ALL ON FUNCTIONS TO regress_dump_test_role;\E /xm, like => { %full_runs, %dump_test_schema_runs, section_post_data => 1, }, @@ -600,7 +600,7 @@ my %tests = ( regexp => qr/^ \QALTER DEFAULT PRIVILEGES \E \QFOR ROLE regress_dump_test_role \E - \QREVOKE ALL ON FUNCTIONS FROM PUBLIC;\E + \QREVOKE ALL ON FUNCTIONS FROM PUBLIC;\E /xm, like => { %full_runs, section_post_data => 1, }, unlike => { no_privs => 1, }, @@ -615,10 +615,10 @@ my %tests = ( regexp => qr/^ \QALTER DEFAULT PRIVILEGES \E \QFOR ROLE regress_dump_test_role \E - \QREVOKE ALL ON TABLES FROM regress_dump_test_role;\E\n + \QREVOKE ALL ON TABLES FROM regress_dump_test_role;\E\n \QALTER DEFAULT PRIVILEGES \E \QFOR ROLE regress_dump_test_role \E - \QGRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,VACUUM,ANALYZE,UPDATE ON TABLES TO regress_dump_test_role;\E + \QGRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,VACUUM,ANALYZE,UPDATE ON TABLES TO regress_dump_test_role;\E /xm, like => { %full_runs, section_post_data => 1, }, unlike => { no_privs => 1, },

Message-ID: <20221206232744.GA3560301@nathanxps13>
Permalink:  ../20221206232744.GA3560301@nathanxps13/
Also on:    postgresql.org/message-id/20221206232744.GA3560301@nathanxps13

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com
  Subject: Re: remove extra space from dumped ALTER DEFAULT PRIVILEGES commands
  In-Reply-To: <20221206232744.GA3560301@nathanxps13>
  References: <20221206232744.GA3560301@nathanxps13>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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