Re: to_regtype() Raises Error

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Vik Fearing <vik(at)postgresfriends(dot)org>, Erik Wienhold <ewie(at)ewie(dot)name>, "David E(dot) Wheeler" <david(at)justatheory(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: to_regtype() Raises Error
Date: 2023-09-17 23:49:22
Message-ID: dff83c6b2f05a222daa0eca85a103eaae305c49d.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 2023-09-18 at 00:57 +0200, Vik Fearing wrote:
> On 9/18/23 00:41, Erik Wienhold wrote:
> > On 18/09/2023 00:13 CEST David E. Wheeler <david(at)justatheory(dot)com> wrote:
> > > The docs for `to_regtype()` say, “this function will return NULL rather than
> > > throwing an error if the name is not found.” And it’s true most of the time:
> > >
> > > david=# select to_regtype('foo'), to_regtype('clam');
> > >   to_regtype | to_regtype
> > > ------------+------------
> > >   [null]     | [null]
> > >
> > > But not others:
> > >
> > > david=# select to_regtype('inteval second');
> > > ERROR:  syntax error at or near "second"
> > > LINE 1: select to_regtype('inteval second');
> > >                  ^
> > > CONTEXT:  invalid type name "inteval second”
> >
> > Probably a typo and you meant 'interval second' which works.
> No, that is precisely the point.  The result should be null instead of
> an error.

Right. I debugged into this, and found this comment to typeStringToTypeName():

* If the string cannot be parsed as a type, an error is raised,
* unless escontext is an ErrorSaveContext node, in which case we may
* fill that and return NULL. But note that the ErrorSaveContext option
* is mostly aspirational at present: errors detected by the main
* grammar, rather than here, will still be thrown.

"escontext" is an ErrorSaveContext node, and it is the parser failing.

Not sure if we can do anything about that or if it is worth the effort.

Perhaps the documentation could reflect the implementation.

Yours,
Laurenz Albe

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2023-09-18 00:40:22 Re: Add 'worker_type' to pg_stat_subscription
Previous Message Peter Geoghegan 2023-09-17 23:47:45 Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan