From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | "D'Arcy Cain" <darcy(at)druid(dot)net> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: COMMUTATOR doesn't seem to work |
Date: | 2012-06-22 23:09:11 |
Message-ID: | CA+TgmobY0gKqHaGW-dZdLqQQGh75_f846D90HTLUbqyQCeY+qA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jun 22, 2012 at 12:28 PM, D'Arcy Cain <darcy(at)druid(dot)net> wrote:
>> I doubt that an "auto reverse the arguments" facility would be very
>> much cheaper. You could maybe argue that the aggregated maintenance
>> and space costs of all the commutator-pair functions are enough to
>> justify having some such solution instead, but I'm doubtful --- and
>> even if true, getting from here to there would be painful.
>
>
> And it would only apply to a very specific type of function.
>
> The other idea I had was to just have the second C function call the
> first but that didn't work. Here is what I tried.
>
> PG_FUNCTION_INFO_V1(chkpass_eq);
> Datum
> chkpass_eq(PG_FUNCTION_ARGS)
> {
> chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
> text *a2 = (text *) PG_GETARG_TEXT_P(1);
> char str[9];
>
> strlcpy(str, a2->vl_dat, sizeof(str));
> PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
> }
>
> PG_FUNCTION_INFO_V1(chkpass_eq2);
> Datum
> chkpass_eq2(PG_FUNCTION_ARGS)
> {
> return chkpass_eq(PG_GETARG_POINTER(1), PG_GETARG_TEXT_P(0));
> }
>
> Now in this specific case the function is trivial and writing it twice
> is no big deal but in general I hate writing the same code twice. I
> suppose I could extract the actual operation out to a third function
> and call it from the others. I may do that anyway just for the value
> of the example. Or is there a way to do what I tried above?
I think DirectionFunctionCall2 is what you want.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2012-06-23 00:47:15 | Re: pg_prewarm |
Previous Message | Robert Haas | 2012-06-22 23:06:55 | Re: random failing builds on spoonbill - backends not exiting... |