Re: COMMUTATOR doesn't seem to work

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: COMMUTATOR doesn't seem to work
Дата
Msg-id CA+TgmobY0gKqHaGW-dZdLqQQGh75_f846D90HTLUbqyQCeY+qA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: COMMUTATOR doesn't seem to work  (D'Arcy Cain <darcy@druid.net>)
Ответы Re: COMMUTATOR doesn't seem to work  (D'Arcy Cain <darcy@druid.net>)
Список pgsql-hackers
On Fri, Jun 22, 2012 at 12:28 PM, D'Arcy Cain <darcy@druid.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: random failing builds on spoonbill - backends not exiting...
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: pg_prewarm