Re: regclass and format('%I') - Mailing list pgsql-general

From Jason Dusek
Subject Re: regclass and format('%I')
Date
Msg-id CAO3NbwP9dKQ=tYGjDFFKD6Pza60YjZoEKNA2w0YFfXUuO9zR_A@mail.gmail.com
Whole thread Raw
In response to Re: regclass and format('%I')  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: regclass and format('%I')  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
On 14 March 2015 at 09:17, David G. Johnston <david.g.johnston@gmail.com> wrote:
> On Saturday, March 14, 2015, Jason Dusek <jason.dusek@gmail.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.

Kind Regards,
  Jason Dusek


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: is there a relationship between indexes and temporary file creation?
Next
From: Pavel Stehule
Date:
Subject: Re: regclass and format('%I')