From 116d2bba7eeaf25c544bc187e3ad2a8677a9a22c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 19 Jun 2001 22:39:12 +0000 Subject: Add IS UNKNOWN, IS NOT UNKNOWN boolean tests, fix the existing boolean tests to return the correct results per SQL9x when given NULL inputs. Reimplement these tests as well as IS [NOT] NULL to have their own expression node types, instead of depending on special functions. From Joe Conway, with a little help from Tom Lane. --- src/backend/parser/parse_coerce.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/backend/parser/parse_coerce.c') diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 38f044217e..283fd30240 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.57 2001/05/22 16:37:16 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.58 2001/06/19 22:39:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -321,6 +321,30 @@ coerce_type_typmod(ParseState *pstate, Node *node, } +/* coerce_to_boolean() + * Coerce an argument of a construct that requires boolean input + * (AND, OR, NOT, etc). + * + * If successful, update *pnode to be the transformed argument (if any + * transformation is needed), and return TRUE. If fail, return FALSE. + * (The caller must check for FALSE and emit a suitable error message.) + */ +bool +coerce_to_boolean(ParseState *pstate, Node **pnode) +{ + Oid inputTypeId = exprType(*pnode); + Oid targetTypeId; + + if (inputTypeId == BOOLOID) + return true; /* no work */ + targetTypeId = BOOLOID; + if (! can_coerce_type(1, &inputTypeId, &targetTypeId)) + return false; /* fail, but let caller choose error msg */ + *pnode = coerce_type(pstate, *pnode, inputTypeId, targetTypeId, -1); + return true; +} + + /* select_common_type() * Determine the common supertype of a list of input expression types. * This is used for determining the output type of CASE and UNION -- cgit v1.2.1