Re: Casting

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Casting
Date: 2003-04-10 02:49:52
Message-ID: 815.1049942992@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

"Nigel J. Andrews" <nandrews(at)investsystems(dot)co(dot)uk> writes:
> 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

I've applied the attached patch to fix this.

regards, tom lane

*** REL7_3/src/backend/parser/parse_coerce.c.orig Thu Oct 24 18:09:00 2002
--- REL7_3/src/backend/parser/parse_coerce.c Wed Apr 9 22:47:57 2003
***************
*** 226,251 ****
result = (Node *) makeRelabelType(result, targetTypeId, -1,
cformat);
}
-
- /*
- * If the input is a constant, apply the type conversion
- * function now instead of delaying to runtime. (We could, of
- * course, just leave this to be done during
- * planning/optimization; but it's a very frequent special
- * case, and we save cycles in the rewriter if we fold the
- * expression now.)
- *
- * Note that no folding will occur if the conversion function is
- * not marked 'immutable'.
- *
- * HACK: if constant is NULL, don't fold it here. This is needed
- * by make_subplan(), which calls this routine on placeholder
- * Const nodes that mustn't be collapsed. (It'd be a lot
- * cleaner to make a separate node type for that purpose...)
- */
- if (IsA(node, Const) &&
- !((Const *) node)->constisnull)
- result = eval_const_expressions(result);
}
else
{
--- 226,231 ----
***************
*** 496,502 ****
{
List *args;
Const *cons;
- Node *fcall;

/* Pass given value, plus target typmod as an int4 constant */
cons = makeConst(INT4OID,
--- 476,481 ----
***************
*** 523,541 ****
args = lappend(args, cons);
}

! fcall = build_func_call(funcId, targetTypeId, args, cformat);
!
! /*
! * If the input is a constant, apply the length coercion
! * function now instead of delaying to runtime.
! *
! * See the comments for the similar case in coerce_type.
! */
! if (node && IsA(node, Const) &&
! !((Const *) node)->constisnull)
! node = eval_const_expressions(fcall);
! else
! node = fcall;
}

return node;
--- 502,508 ----
args = lappend(args, cons);
}

! node = build_func_call(funcId, targetTypeId, args, cformat);
}

return node;

In response to

  • Casting at 2003-04-08 09:04:30 from Nigel J. Andrews

Responses

  • Re: Casting at 2003-04-10 08:12:37 from Nigel J. Andrews

Browse pgsql-general by date

  From Date Subject
Next Message Paul Ramsey 2003-04-10 03:46:10 OS/X and PL/PGSQL
Previous Message Juraj Fedel 2003-04-10 01:28:25 Database Dezign for begginers

Browse pgsql-hackers by date

  From Date Subject
Next Message Santosa Budi 2003-04-10 03:53:13 medical image on postgreSQL?
Previous Message Tom Lane 2003-04-10 02:15:29 Re: More thoughts about FE/BE protocol