Next sample of parser hook using:
attachment contains module that transform every empty string to null.
I am not sure, if this behave is exactly compatible with Oracle, but
for first iteration it is good.
postgres=# select length('') is null;
?column?
----------
t
(1 row)
I thing, so this should be used for emulation of some constructors too.
Regards
Pavel Stehule
2009/2/13 Peter Eisentraut <[email protected]>:
> Heikki Linnakangas wrote:
>>
>> And on top of that, decode() is supposed to do short-circuit evaluation of
>> the arguments.
>
> Then the only solution is to hack it right into the parser.
>
> There is an existing decode() function however ...
>
/*-------------------------------------------------------------------------
*
* null.c
*
*
* Copyright (c) 2008-2009, PostgreSQL Global Developent Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.4
2009/01/05 13:35:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "parser/parse_expr.h"
PG_MODULE_MAGIC;
/* Saved hook value */
static ParseExprTransform_hook_type prev_transformExpr = NULL;
void _PG_init(void);
void _PG_fini(void);
static Node * transformEmptyStr(ParseState *pstate, Node *expr);
/*
* Module load callback
*/
void
_PG_init(void)
{
/* Install hooks. */
prev_transformExpr = ParseExprTransform_hook;
ParseExprTransform_hook = transformEmptyStr;
}
/*
* Module unload callback
*/
void
_PG_fini(void)
{
/* Uninstall hooks. */
ParseExprTransform_hook = prev_transformExpr;
}
/*
* Decode transform hook. When I diagnose decode func call, I transform it.
*/
Node *
transformEmptyStr(ParseState *pstate, Node *expr)
{
A_Const *c = (A_Const *) expr;
if (c->val.type == T_String && *c->val.val.str == '\0')
{
A_Const *n = makeNode(A_Const);
n->val.type = T_Null;
n->location = c->location;
expr = (Node *) n;
}
if (prev_transformExpr)
return prev_transformExpr(pstate, expr);
else
return standard_transformExpr(pstate, expr);
}
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers