| From: | D'Arcy Cain <darcy(at)druid(dot)net> |
|---|---|
| To: | Florian Pflug <fgp(at)phlo(dot)org> |
| 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 15:12:50 |
| Message-ID: | 4FE48B72.8040605@druid.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 12-06-22 07:11 AM, Florian Pflug wrote:
> On Jun22, 2012, at 06:32 , D'Arcy Cain wrote:
>> So I have my type working now but I had to create a new C function
>> that take the opposite argument order. Seems redundant but I could
>> not see a better way.
>
> There isn't. Postgres itself contains a huge number of such functions,
> e.g. for every *lt() (less-than) there's a *gt() (greater-than).
Right but that's not the same thing. Assuming you meant lt/gte and
lte/gt those still are not self-commutating (SC). For example, '='
on two ints is SC. The issue here is that the operator is SC but
the args are different types. It would be nice if there was a way
to automatically generate code that reverses arguments. Maybe such
a thing belongs in the CREATE FUNCTION command.
Or, I guess this works and keeps from creating a second C function:
CREATE OR REPLACE FUNCTION eq(chkpass, text)
RETURNS bool
STRICT
AS 'chkpass.so', 'chkpass_eq'
LANGUAGE 'c'
RETURNS NULL ON NULL INPUT;
CREATE OR REPLACE FUNCTION eq(text, chkpass)
RETURNS bool
AS 'select eq($2, $1);'
LANGUAGE SQL
RETURNS NULL ON NULL INPUT;
--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
IM: darcy(at)Vex(dot)Net
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2012-06-22 15:29:18 | Re: Allow WAL information to recover corrupted pg_controldata |
| Previous Message | Robert Haas | 2012-06-22 14:59:45 | Re: [PATCH 01/16] Overhaul walsender wakeup handling |