Re: to_regtype() Raises Error - Mailing list pgsql-hackers

From Laurenz Albe
Subject Re: to_regtype() Raises Error
Date
Msg-id dff83c6b2f05a222daa0eca85a103eaae305c49d.camel@cybertec.at
Whole thread Raw
In response to Re: to_regtype() Raises Error  (Vik Fearing <vik@postgresfriends.org>)
List 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@justatheory.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



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan
Next
From: Peter Smith
Date:
Subject: Re: Add 'worker_type' to pg_stat_subscription