Re: Create duplicate of existing operator

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andy Chambers <achambers(at)mcna(dot)net>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create duplicate of existing operator
Date: 2012-02-17 03:35:35
Message-ID: 11505.1329449735@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andy Chambers <achambers(at)mcna(dot)net> writes:
> Is it possible to use CREATE OPERATOR to make "&&" behave like "and"?

Hmm ... AND is not really an operator, but a primitive expression
construct. So I was about to say "no", but then it occurred to me
you could do something like (untested):

create function nonstandard_and(bool,bool) returns bool as
'select $1 and $2' language sql;

create operator && (procedure = nonstandard_and, leftarg = bool,
rightarg = bool);

This would be completely unworkable unless the implementation function
is an inline-able SQL function, because otherwise the planner will not
recognize that your && means AND, resulting in spectacularly bad
optimization. But with that, maybe you could get away with it.

I would not recommend it though, because you'll be paying through the
nose (inlining isn't a remarkably cheap operation) for what
fundamentally is gratuitously nonstandard, unportable SQL syntax with no
obvious redeeming value. The above hack is a cute hack, but it's just a
hack not something I'd recommend for production.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Weiss 2012-02-17 04:16:04 Re: MD5 salt in pg_authid password hashes
Previous Message Andy Chambers 2012-02-17 03:08:25 Create duplicate of existing operator