pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18730: Inequality comparison operators and SMALLINT negative immediate value
2+ messages / 2 participants
[nested] [flat]

* BUG #18730: Inequality comparison operators and SMALLINT negative immediate value
@ 2024-12-03 01:31  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2024-12-03 01:31 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: nat@makarevitch.org

The following bug has been logged on the website:

Bug reference:      18730
Logged by:          Nat Makarevitch
Email address:      nat@makarevitch.org
PostgreSQL version: 17.2
Operating system:   Linux
Description:        

Hi!

create table test_smallint(smint smallint);

insert into test_smallint values (-1);

select * from test_smallint where smint<>-2;
 smint 
═══════
    -1
(1 row)

BEWARE: there is a space between '=' and '-':
select * from test_smallint where smint!= -2;
 smint 
═══════
    -1
(1 row)

So far, so good.

BEWARE: there isn't any space between '=' and '-':
select * from test_smallint where smint!=-2;
ERROR:  operator does not exist: smallint !=- integer
LINE 1: select * from test_smallint where smint!=-2;
                                               ^
HINT:  No operator matches the given name and argument types. You might need
to add explicit type casts.

Isn't the operator "!=" theoritically "an alias, which is converted to <> at
a very early stage of parsing" (as per
https://www.postgresql.org/docs/17/functions-comparison.html )?

AFAIK there is no "=-" alias/macro, and I can't see any reason to implicitly
cast "-2" to INTEGER while "2" type stays inferred.

Thank you!



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #18730: Inequality comparison operators and SMALLINT negative immediate value
@ 2024-12-03 13:48  David G. Johnston <david.g.johnston@gmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2024-12-03 13:48 UTC (permalink / raw)
  To: nat@makarevitch.org <nat@makarevitch.org>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Monday, December 2, 2024, PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      18730
> Logged by:          Nat Makarevitch
> Email address:      nat@makarevitch.org
> PostgreSQL version: 17.2
> Operating system:   Linux
> Description:
>
> BEWARE: there isn't any space between '=' and '-':
> select * from test_smallint where smint!=-2;
> ERROR:  operator does not exist: smallint !=- integer
> LINE 1: select * from test_smallint where smint!=-2;
>                                                ^
> HINT:  No operator matches the given name and argument types. You might
> need
> to add explicit type casts.


The operator !=- is allowed per [1], since it contains !, so the parser
captures the - as per of the operator as opposed to leaving - as a break
character.

1.
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS


> Isn't the operator "!=" theoritically "an alias, which is converted to <>
> at
> a very early stage of parsing" (as per
> https://www.postgresql.org/docs/17/functions-comparison.html )?


The != operator and !=- operators are two different operators.  Only the
former is converted to <>, and not any symbol subsequence of those two
characters.

David J.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-12-03 13:48 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-03 01:31 BUG #18730: Inequality comparison operators and SMALLINT negative immediate value PG Bug reporting form <noreply@postgresql.org>
2024-12-03 13:48 ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox