summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_coerce.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-06-19 22:39:12 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-06-19 22:39:12 +0000
commit116d2bba7eeaf25c544bc187e3ad2a8677a9a22c (patch)
treec77a6b20a3acdbb6e25a1fc4a561c0e839ddbb1e /src/backend/parser/parse_coerce.c
parent8c30aca2ba1a48d38b1206f8559d1dc6b65c5ca7 (diff)
downloadpostgresql-116d2bba7eeaf25c544bc187e3ad2a8677a9a22c.tar.gz
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.
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r--src/backend/parser/parse_coerce.c26
1 files changed, 25 insertions, 1 deletions
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