Re: [REVIEW] Tab Completion for CREATE DATABASE ... TEMPLATE ...

From: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Kevin Grittner <kgrittn(at)gmail(dot)com>, Sehrope Sarkuni <sehrope(at)jackdb(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [REVIEW] Tab Completion for CREATE DATABASE ... TEMPLATE ...
Date: 2016-09-12 02:52:17
Message-ID: CAKOSWNkedmk6e21Wsx=xm_odp3SKpkdNZb1QaHDh8wZSBx9qVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 9/11/16, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com> writes:
>> On 9/11/16, Kevin Grittner <kgrittn(at)gmail(dot)com> wrote:
>>> I was able to find cases during test which were not handled
>>> correctly with either version, so I tweaked the query a little.
>
>> Hmm. Which one? Attempt to "SET ROLE <grouprole>"?
>> Unfortunately, I after reading your letter I realized that I missed a
>> case (it is not working even with your version):
>
> I wasn't aware that this patch was doing anything nontrivial ...
>
> After looking at it I think it's basically uninformed about how to test
> for ownership. An explicit join against pg_roles is almost never the
> right way for SQL queries to do that. Lose the join and write it more
> like this:
>
> +"SELECT pg_catalog.quote_ident(d.datname) "\
> +" FROM pg_catalog.pg_database d "\
> +" WHERE substring(pg_catalog.quote_ident(d.datname),1,%d)='%s' "\
> +" AND (d.datistemplate OR pg_catalog.pg_has_role(d.datdba, 'USAGE'))"
>
> See the information_schema views for precedent.
>
> regards, tom lane

Wow! I have not pay enough attention to a description of "pg_has_role".
Your version works for all my tests. Thank you.

--
Best regards,
Vitaly Burovoy

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2016-09-12 04:28:44 Re: patch: function xmltable
Previous Message Amit Kapila 2016-09-12 02:46:45 Re: Write Ahead Logging for Hash Indexes