BUG #19948: Unqualified prefix <= operator is rejected despite being first in search_path

Started by PG Bug reporting form3 days ago2 messagesbugs

Thread notes

1 note#bug#not-a-bug
hackorum-bot#bug#not-a-bug
hackorum-bot
2 days ago

@global #bug #not-a-bug

#bug#not-a-bug
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 19948
Logged by: Faye
Email address: imchifan@mail.com
PostgreSQL version: 19.0
Operating system: Linux/amd64
Description:

Hi,

A user-defined prefix operator named <= can be created and invoked with
qualified OPERATOR(...) syntax, but the equivalent unqualified expression is
rejected with SQLSTATE 42601 even when its schema is first in search_path.

The following can be run as a superuser with psql -X -f repro.sql:

BEGIN;

CREATE SCHEMA ops;

CREATE FUNCTION ops.unary_le(integer)
RETURNS boolean
LANGUAGE sql
IMMUTABLE STRICT
AS 'SELECT $1 <= 10';

CREATE OPERATOR ops.<= (
FUNCTION = ops.unary_le,
RIGHTARG = integer
);

SET LOCAL search_path = ops, pg_catalog;

SELECT OPERATOR(ops.<=) 5 AS qualified_prefix_works;

DO $test$
BEGIN
BEGIN
EXECUTE 'SELECT <= 5';
RAISE EXCEPTION 'unqualified prefix <= unexpectedly parsed';
EXCEPTION
WHEN SQLSTATE '42601' THEN
RAISE NOTICE 'unqualified prefix <= rejected with SQLSTATE 42601';
END;
END
$test$;

ROLLBACK;

The relevant output is:

qualified_prefix_works
------------------------
t
(1 row)

NOTICE: unqualified prefix <= rejected with SQLSTATE 42601

The successful qualified invocation shows that the prefix operator is valid
and visible. PostgreSQL's documentation permits prefix operators and lists
<= among valid operator spellings, so the unqualified prefix expression
should parse and resolve through search_path as other user-defined prefix
operators do.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PG Bug reporting form (#1)
Re: BUG #19948: Unqualified prefix <= operator is rejected despite being first in search_path

PG Bug reporting form <noreply@postgresql.org> writes:

A user-defined prefix operator named <= can be created and invoked with
qualified OPERATOR(...) syntax, but the equivalent unqualified expression is
rejected with SQLSTATE 42601 even when its schema is first in search_path.

Don't hold your breath waiting for a fix for that. "<=", like some
other operators standardized by the SQL standard, has its own
productions in our Bison grammar, and must do so in order to receive
the correct operator-precedence treatment. We could perhaps enable
this by adding explicit grammar productions for all those operators in
prefix form, but it seems like it'd bloat the grammar (with ensuing
performance consequences) for little real-world return. You can't
use "<", "=", ">", ">=", "<>", "*", "/", and probably some other
standard binary operators as prefix operators either, and there have
been basically no complaints about that in 30 years.

regards, tom lane