Re: Patch: Allow SQL-language functions to reference parameters by parameter name

From: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
To: Matthew Draper <matthew(at)trebex(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch: Allow SQL-language functions to reference parameters by parameter name
Date: 2012-01-19 09:58:59
Message-ID: CAP7QgmkzZt_thq4NxswTHhMwt7FOgxD=zOuy1pc8Hp_cSMMCog@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 18, 2012 at 1:11 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
> On Sat, Jan 14, 2012 at 8:10 AM, Matthew Draper <matthew(at)trebex(dot)net> wrote:
>>
>> I just remembered to make time to advance this from WIP to proposed
>> patch this week... and then worked out I'm rudely dropping it into the
>> last commitfest at the last minute. :/
>
> The patch applies clean against master but compiles with warnings.
> functions.c: In function ‘prepare_sql_fn_parse_info’:
> functions.c:212: warning: unused variable ‘argnum’
> functions.c: In function ‘sql_fn_post_column_ref’:
> functions.c:341: warning: implicit declaration of function ‘ParseFuncOrColumn’
> functions.c:345: warning: assignment makes pointer from integer without a cast
>
> (Now it occurred to me that forgetting the #include parse_func.h might
> hit this breakage..., so I'll fix it here and continue to test, but if
> you'll fix it yourself, let me know)

I fixed it here and it now works with my environment. The regression
tests pass, the feature seems working as aimed, but it seems to me
that it needs more test cases and documentation. For the tests, I
believe at least we need "ambiguous" case given upthread, so that we
can ensure to keep compatibility. For the document, it should describe
the name resolution rule, as stated in the patch comment.

Aside from them, I wondered at first what if the function is
schema-qualified. Say,

CREATE FUNCTION s.f(a int) RETURNS int AS $$
SELECT b FROM t WHERE a = s.f.a
$$ LANGUAGE sql;

It actually errors out, since function-name-qualified parameter only
accepts function name without schema name, but it looked weird to me
at first. No better idea from me at the moment, though.

I mark this "Waiting on Author" for now.

Thanks,
--
Hitoshi Harada

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hitoshi Harada 2012-01-19 10:08:52 Re: Publish checkpoint timing and sync files summary data to pg_stat_bgwriter
Previous Message Gražvydas Valeika 2012-01-19 09:13:16 Re: Strange primary key constraint influence to grouping