V0.2 patch for TODO Item: SQL-language reference parameters by name.

From: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
To: <pgsql-patches(at)postgresql(dot)org>
Cc: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: V0.2 patch for TODO Item: SQL-language reference parameters by name.
Date: 2007-11-03 11:36:45
Message-ID: 000401c81e0d$d0ca8300$0a01a8c0@gevmus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Hello All,

This patch implements a (generic) callback functionality in the parser.
The mechanism can be used to send callback messages from within the parser
to external functions.

I would like to know your opinion about the following:

In previous discussion Tom referred to:

>One point here is that it would be good to be able to qualify the argument
names with the function name, for example
> create function myfunc(x int) ...
> select ... from t where t.x = myfunc.x

The above is possible but I think qualifying the argument names with the
function name
can be cumbersome when one has to provide the function name multiple times.
For example: (where clause)

create or replace function sp_item_get_by_type_or_category(p_type
integer,p_category integer)
returns setof item_view as
$$
select ..... from item_view i
inner join tblcategory c on i.catid = c.catid
inner join tbltype t on i.typeid = t.typeid
where
c.catid = sp_item_get_by_type_or_category.p_category or
t.typeid = sp_item_get_by_type_or_categor.p_type;
$$
language sql;

Perhaps we could use the word "this" instead of the entire function name

For example:
....
where
c.catid = this.p_category or
t.typeid = this.p_type;
....

Any thoughts?

Regards,
Gevik

************************************************************************
PLEASE NOTE:
- This patch in created with MSVC++
- Resolving the argnames is not yet implemented correctly
due above.
- Two files have been added parse_callback.h and .c

How does it work:

>>> To setup callback;

ParserCallbackContext sqlcallbackcontext;

/* attaching parser callback handler*/
sqlcallbackcontext.context = T_ParsingFunctionBody;
sqlcallbackcontext.ctxarg = tuple;
sqlcallbackcontext.callback = sql_parser_callback_handler;
sqlcallbackcontext.previous = parser_callback_context_stack;
parser_callback_context_stack = &sqlcallbackcontext;
....
....
parser_callback_context_stack = sqlcallbackcontext.previous;

>>> To call the callback handler from within the parser:

ParserCallbackContextArgs args;
args.pstate = pstate;
args.input = (Node *)cref;
args.action = A_ResolveAmbigColumnRef;
parser_do_callback(&args);

To handle the callback:

if(context == T_ParsingFunctionBody)
{
switch(action)
{
case A_ResolveAmbigColumnRef:
....
}
}

Attachment Content-Type Size
patch-0.2.txt text/plain 8.2 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message David Fetter 2007-11-03 15:56:40 Re: V0.2 patch for TODO Item: SQL-language reference parameters by name.
Previous Message Magnus Hagander 2007-11-02 21:00:06 Re: krb_match_realm