On 2014-04-04 11:18:10 -0400, Robert Haas wrote:
> On Wed, Apr 2, 2014 at 11:27 PM, Amit Kapila <amit.kapil...@gmail.com> wrote:
> > Right, it will get reset in error. However still we need to free for 
> > missing_ok
> > case and when it is successful in getting typeid. So don't you think it is
> > better to just free once before calling LookupTypeName()?
> >
> > The code is right in it's current form as well, it's just a minor suggestion
> > for improvement, so if you think current way the code written is okay, then
> > ignore this suggestion.
> 
> I see.  Here's an updated patch with a bit of minor refactoring to
> clean that up, and some improvements to the documentation.
> 
> I was all ready to commit this when I got cold feet.  What's bothering
> me is that the patch, as written, mimics the exact behavior of the
> text->regproc cast, including the fact that the supplying an OID,
> written as a number, will always return that OID, whether it exists or
> not:
> 
> rhaas=# select to_regclass('1259'), to_regclass('pg_class');
>  to_regclass | to_regclass
> -------------+-------------
>  pg_class    | pg_class
> (1 row)
> 
> rhaas=# select to_regclass('12590'), to_regclass('does_not_exist');
>  to_regclass | to_regclass
> -------------+-------------
>  12590       |
> (1 row)
> 
> I think that's unacceptably weird behavior.  My suggestion is to
> restructure the code so that to_regclass() only accepts a name, not an
> OID, and make its charter precisely to perform a name lookup and
> return an OID (as regclass) or NULL if there's no match.

There's actually another good reason to not copy regclass's behaviour:

postgres=# CREATE TABLE "123"();
CREATE TABLE
postgres=# SELECT '123'::regclass;
 regclass
 ----------
  123
  (1 row)

I don't think that's fixable for ::regclass, but we shouldn't copy it.

Greetings,

Andres Freund

-- 
 Andres Freund                     http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to