Create duplicate of existing operator

Started by Andy Chambersabout 14 years ago2 messagesgeneral
Jump to latest
#1Andy Chambers
achambers@mcna.net

Hi,

Is it possible to use CREATE OPERATOR to make "&&" behave like "and"? In
general, for the built-in operators, is it possible to see their "CREATE
OPERATOR" statements?

Cheers,
Andy

--

Andy Chambers
*Software Engineer
*

*MCNA Dental Plans*
200 West Cypress Creek Road
Suite 500
Fort Lauderdale, FL 33309

954-730-7131 X186 (Office)
954-628-3347 (Fax)
1-800-494-6262 X141 (Toll Free)

achambers@mcna.net <glipari@mcna.net> (Email)

www.mcna.net (Website)

CONFIDENTIALITY NOTICE: This electronic mail may contain information that
is privileged, confidential, and/or otherwise protected from disclosure to
anyone other than its intended recipient(s). Any dissemination or use of
this electronic mail or its contents by persons other than the intended
recipient(s) is strictly prohibited. If you have received this
communication in error, please notify the sender immediately by reply
e-mail so that we may correct our internal records. Please then delete the
original message. Thank you.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andy Chambers (#1)
Re: Create duplicate of existing operator

Andy Chambers <achambers@mcna.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