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

From Tom Lane
Subject Re: regclass and format('%I')
Date
Msg-id 17367.1426346951@sss.pgh.pa.us
Whole thread Raw
In response to Re: regclass and format('%I')  (Jason Dusek <jason.dusek@gmail.com>)
Responses Re: regclass and format('%I')
List pgsql-general
Jason Dusek <jason.dusek@gmail.com> writes:
> It honestly seems far more reasonable to me that %s and %I should do
> the exact same thing with regclass.

You're mistaken.  The operation of format() is first to convert the
non-format arguments to text strings, using the output functions for their
data types, and then to further process those text strings according to
the format specifiers:

%s -- no additional processing, just insert the string as-is.
%I -- apply double-quoting transformation to create a valid SQL identifier.
%L -- apply single-quoting transformation to create a valid SQL literal.

In the case of regclass, the output string is already double-quoted
as necessary, so applying %I to it produces a doubly double-quoted
string which is almost certainly not what you want.  But it's not
format()'s job to be smarter than the user.  If it tried to avoid
an extra pass of double quoting, it would get some cases wrong,
potentially creating security holes.

            regards, tom lane


pgsql-general by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: Basic Question on Point In Time Recovery
Next
From: "David G. Johnston"
Date:
Subject: Re: regclass and format('%I')