From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Jason Dusek <jason(dot)dusek(at)gmail(dot)com> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: regclass and format('%I') |
Date: | 2015-03-15 05:20:20 |
Message-ID: | CAFj8pRB79A0xGHmviiafE=ZLGTWNZU3zT4ar-j0uF_p-5VV6kQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2015-03-15 3:09 GMT+01:00 Jason Dusek <jason(dot)dusek(at)gmail(dot)com>:
> On 14 March 2015 at 09:17, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
> > On Saturday, March 14, 2015, Jason Dusek <jason(dot)dusek(at)gmail(dot)com> wrote:
> >> It honestly seems far more reasonable to me that %s and %I should do
> >> the exact same thing with regclass. My reasoning is as follows:
> >>
> >> ‘%I’ formats a something such that it is a valid identifier,
> >>
> >> regclass is already a valid identifier,
> >>
> >> therefore, do nothing.
> >>
> >> Another line of reasoning:
> >>
> >> If you format with ‘%s’ you are saying: I don’t care whether it’s a
> >> valid identifier or literal or whatever, just put the string there,
> >>
> >> but when we sub a regclass into a string, we want it to be a valid
> >> identifier,
> >>
> >> therefore we should write ‘%I’ when subbing it, so as not to confuse
> >> our readers,
> >>
> >> therefore ‘%I’ should do nothing.
> >>
> >
> > I agree with the theory but adding type specific logic to format is
> going to
> > be difficult. The first thing the system does is convert all of the
> inputs
> > to text. Inside format() everything is text and so it has no way to know
> > that the type was regclass and should not be quoted again.
>
> Could it work to add type-specific logic for the cast from `regclass`
> to `name`? It would be nice to have something formulaic: always format
> identifiers with `%I`, always cast to `name` before formatting.
>
I don't think, so it can help - first, it is workaround and it doesn't help
for somebody who doesn't read a documentation. Same effect you can get if
you write "doesn't use %I for regclass, regtype types", although this
sentence is strange. I agree with you so it is bug or minimally not user
friendly design.
A some good solution should be safe function quote_identif, that protect us
against double quoting. This logic should be elsewhere than inside "format"
function. I am thinking so we can do it. It breaks nothing. Implementation
should not be too much complex, because "new" function quote_identif can do
nothing for safe types, so it can take string as input parameter and typid
as second parameter.
Pavel
>
> Kind Regards,
> Jason Dusek
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2015-03-15 06:18:13 | Re: regclass and format('%I') |
Previous Message | Jason Dusek | 2015-03-15 02:09:44 | Re: regclass and format('%I') |