1

Anyone knows how to call self defined operator in postgresql?
I hava the following operator:

CREATE OR REPLACE FUNCTION algo.fun_temp(IN exp BOOLEAN)
RETURNS INTEGER AS $$
BEGIN
    RETURN NOT exp;
END;
$$ LANGUAGE plpgsql;

CREATE OPERATOR algo.~
(
PROCEDURE = algo.fun_temp,
RIGHTARG = BOOLEAN
);

And when I try to call this operator with SELECT algo.~ TRUE, the client complains

"ERROR:  syntax error at or near "~"
LINE 1: SELECT algo.~ TRUE"

Anyone knows what the problem is? Any help is appreciated.

cheng

1 Answer 1

1

The function should return INTEGER, what you wrote returns BOOLEAN:

CREATE OR REPLACE FUNCTION algo.fun_temp(IN exp BOOLEAN)
RETURNS INTEGER AS $$
BEGIN
    RETURN (NOT exp)::INTEGER;
END;
$$ LANGUAGE plpgsql;

Then add the schema algo to the search_path:

SET search_path = public, algo;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.