Re: [GENERAL] Casting

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [GENERAL] Casting
Date: 2003-04-08 15:13:30
Message-ID: Pine.LNX.4.21.0304081608400.24319-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, 8 Apr 2003, Tom Lane wrote:

> "Nigel J. Andrews" <nandrews(at)investsystems(dot)co(dot)uk> writes:
> > When I use my cast I get:
> > mydb=> select cast('truE'::text as boolean);
> > WARNING: Error occurred while executing PL/pgSQL function text_to_bool
> > WARNING: line 4 at select into variables
> > ERROR: CopyQuerySnapshot: no snapshot has been set
>
> Hmm. The problem here is that parse_coerce.c thinks it can apply
> eval_const_expressions() to simplify the CAST; but in the general case
> that doesn't work because the query snapshot may not be set yet.
> Had we left the expression to be folded at plan time everything would
> be okay.
>
> I dislike removing the optimization altogether, but maybe we don't
> have much choice. Anyone see another way around it?
>

Well, checking the source, and the comments in there, thanks to Tom's lead I
saw that only immutable functions were folded in the parse. Marking my function
as stable instead of immutable has indeed allowed my test statment above to
run.

So, that could be a published work around, perhaps in the CREATE CAST
page? I'm not sure of the expense of the function being stable and not
immutable though. I suspect it's most likely not a huge cost for many cases.

--
Nigel J. Andrews

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-08 15:16:14 Re: [GENERAL] Casting
Previous Message Bruno Baguette 2003-04-08 15:01:35 How can I indicate the readline location ???

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-04-08 15:16:14 Re: [GENERAL] Casting
Previous Message pgsql 2003-04-08 15:12:11 Re: Complex database for testing, U.S. Census Tiger/UA