Skip to content

Commit 7c1e67b

Browse files
author
Thomas G. Lockhart
committed
Implement IS OF type predicate. Can now do queries of the form:
select value IS OF (integer, float8);
1 parent b71310d commit 7c1e67b

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/backend/parser/parse_expr.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.123 2002/07/18 17:14:19 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.124 2002/08/04 06:46:12 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -282,6 +282,41 @@ transformExpr(ParseState *pstate, Node *expr)
282282
rexpr);
283283
((Expr *)result)->opType = DISTINCT_EXPR;
284284
}
285+
break;
286+
case OF:
287+
{
288+
List *telem;
289+
A_Const *n;
290+
Oid ltype, rtype;
291+
bool matched = FALSE;
292+
293+
/* Checking an expression for match to type.
294+
* Will result in a boolean constant node.
295+
*/
296+
Node *lexpr = transformExpr(pstate,
297+
a->lexpr);
298+
ltype = exprType(lexpr);
299+
foreach(telem, (List *) a->rexpr)
300+
{
301+
rtype = LookupTypeName(lfirst(telem));
302+
matched = (rtype == ltype);
303+
if (matched) break;
304+
}
305+
306+
/* Expect two forms: equals or not equals.
307+
* Flip the sense of the result for not equals.
308+
*/
309+
if (strcmp(strVal(lfirst(a->name)), "!=") == 0)
310+
matched = (! matched);
311+
312+
n = makeNode(A_Const);
313+
n->val.type = T_String;
314+
n->val.val.str = (matched? "t": "f");
315+
n->typename = SystemTypeName("bool");
316+
317+
result = transformExpr(pstate, (Node *) n);
318+
}
319+
break;
285320
}
286321
break;
287322
}
@@ -589,14 +624,14 @@ transformExpr(ParseState *pstate, Node *expr)
589624
break;
590625
}
591626

592-
/*
593-
* Quietly accept node types that may be presented when we are
594-
* called on an already-transformed tree.
595-
*
596-
* Do any other node types need to be accepted? For now we are
597-
* taking a conservative approach, and only accepting node
598-
* types that are demonstrably necessary to accept.
599-
*/
627+
/*********************************************
628+
* Quietly accept node types that may be presented when we are
629+
* called on an already-transformed tree.
630+
*
631+
* Do any other node types need to be accepted? For now we are
632+
* taking a conservative approach, and only accepting node
633+
* types that are demonstrably necessary to accept.
634+
*********************************************/
600635
case T_Expr:
601636
case T_Var:
602637
case T_Const:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy