pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18689: psql : operator "!=" do not behave like "<>"
4+ messages / 4 participants
[nested] [flat]

* BUG #18689: psql : operator "!=" do not behave like "<>"
@ 2024-11-05 11:23 PG Bug reporting form <noreply@postgresql.org>
  2024-11-05 13:02 ` Re: BUG #18689: psql : operator "!=" do not behave like "<>" Rafia Sabih <rafia.pghackers@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Bug reporting form @ 2024-11-05 11:23 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: jhecht@cirilgroup.com

The following bug has been logged on the website:

Bug reference:      18689
Logged by:          Joël HECHT
Email address:      jhecht@cirilgroup.com
PostgreSQL version: 15.6
Operating system:   CentOS Linux release 7.9
Description:        

Hello,

according to the documentation, operators != and <> are supposed to be
interchangeable.
But when operator "!=" is followed by a negative number, the request failed
with an error "No operator matches the given name".

Here is how to reproduce the issue directly with psql :


[postgres@d04f96727d36 ~]$ psql
psql (15.6)
Type "help" for help.

postgres=# select -1<>-1;
 ?column?
----------
 f
(1 row)

postgres=# select -1!=-1;
ERROR:  operator does not exist: integer !=- integer
LINE 1: select -1!=-1;
                 ^
HINT:  No operator matches the given name and argument types. You might need
to add explicit type casts.
postgres=#


Regards.



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

* Re: BUG #18689: psql : operator "!=" do not behave like "<>"
  2024-11-05 11:23 BUG #18689: psql : operator "!=" do not behave like "<>" PG Bug reporting form <noreply@postgresql.org>
@ 2024-11-05 13:02 ` Rafia Sabih <rafia.pghackers@gmail.com>
  2024-11-05 14:56   ` Re: BUG #18689: psql : operator "!=" do not behave like "<>" Tom Lane <tgl@sss.pgh.pa.us>
  2024-11-05 15:05   ` Re: BUG #18689: psql : operator "!=" do not behave like "<>" Erik Wienhold <ewie@ewie.name>
  0 siblings, 2 replies; 4+ messages in thread

From: Rafia Sabih @ 2024-11-05 13:02 UTC (permalink / raw)
  To: jhecht@cirilgroup.com; pgsql-bugs@lists.postgresql.org

Thank you for reporting this. However I found that the lack of space in the
statement is causing this.
On trying it like select -1 != -1; it works fine.

On Tue, 5 Nov 2024 at 13:39, PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      18689
> Logged by:          Joël HECHT
> Email address:      jhecht@cirilgroup.com
> PostgreSQL version: 15.6
> Operating system:   CentOS Linux release 7.9
> Description:
>
> Hello,
>
> according to the documentation, operators != and <> are supposed to be
> interchangeable.
> But when operator "!=" is followed by a negative number, the request failed
> with an error "No operator matches the given name".
>
> Here is how to reproduce the issue directly with psql :
>
>
> [postgres@d04f96727d36 ~]$ psql
> psql (15.6)
> Type "help" for help.
>
> postgres=# select -1<>-1;
>  ?column?
> ----------
>  f
> (1 row)
>
> postgres=# select -1!=-1;
> ERROR:  operator does not exist: integer !=- integer
> LINE 1: select -1!=-1;
>                  ^
> HINT:  No operator matches the given name and argument types. You might
> need
> to add explicit type casts.
> postgres=#
>
>
> Regards.
>
>

-- 
Regards,
Rafia Sabih
CYBERTEC PostgreSQL International GmbH

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

* Re: BUG #18689: psql : operator "!=" do not behave like "<>"
  2024-11-05 11:23 BUG #18689: psql : operator "!=" do not behave like "<>" PG Bug reporting form <noreply@postgresql.org>
  2024-11-05 13:02 ` Re: BUG #18689: psql : operator "!=" do not behave like "<>" Rafia Sabih <rafia.pghackers@gmail.com>
@ 2024-11-05 14:56   ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 4+ messages in thread

From: Tom Lane @ 2024-11-05 14:56 UTC (permalink / raw)
  To: Rafia Sabih <rafia.pghackers@gmail.com>; +Cc: jhecht@cirilgroup.com; pgsql-bugs@lists.postgresql.org

Rafia Sabih <rafia.pghackers@gmail.com> writes:
> Thank you for reporting this. However I found that the lack of space in the
> statement is causing this.
> On trying it like select -1 != -1; it works fine.

Right, see

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

particularly the bit about "A multiple-character operator name cannot
end in + or -, unless ...".  "!=-" will be treated as one operator,
but "<>-" will not.

			regards, tom lane





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

* Re: BUG #18689: psql : operator "!=" do not behave like "<>"
  2024-11-05 11:23 BUG #18689: psql : operator "!=" do not behave like "<>" PG Bug reporting form <noreply@postgresql.org>
  2024-11-05 13:02 ` Re: BUG #18689: psql : operator "!=" do not behave like "<>" Rafia Sabih <rafia.pghackers@gmail.com>
@ 2024-11-05 15:05   ` Erik Wienhold <ewie@ewie.name>
  1 sibling, 0 replies; 4+ messages in thread

From: Erik Wienhold @ 2024-11-05 15:05 UTC (permalink / raw)
  To: Rafia Sabih <rafia.pghackers@gmail.com>; +Cc: jhecht@cirilgroup.com; pgsql-bugs@lists.postgresql.org

On 2024-11-05 14:02 +0100, Rafia Sabih wrote:
> Thank you for reporting this. However I found that the lack of space in the
> statement is causing this.
> On trying it like select -1 != -1; it works fine.

The docs explain it in a bit more detail:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS

"<>" is the standard inequality operator, whereas the operator name "!="
is just an alias implemented by Postgres (and some other RDBMS).  That
alias is subject to the same restrictions as outlined in the linked
docs, i.e., Postgres parses the longer operator name "!=-" because it
contains "!".

> On Tue, 5 Nov 2024 at 13:39, PG Bug reporting form <noreply@postgresql.org>
> wrote:
> 
> > The following bug has been logged on the website:
> >
> > Bug reference:      18689
> > Logged by:          Joël HECHT
> > Email address:      jhecht@cirilgroup.com
> > PostgreSQL version: 15.6
> > Operating system:   CentOS Linux release 7.9
> > Description:
> >
> > Hello,
> >
> > according to the documentation, operators != and <> are supposed to be
> > interchangeable.
> > But when operator "!=" is followed by a negative number, the request failed
> > with an error "No operator matches the given name".
> >
> > Here is how to reproduce the issue directly with psql :
> >
> >
> > [postgres@d04f96727d36 ~]$ psql
> > psql (15.6)
> > Type "help" for help.
> >
> > postgres=# select -1<>-1;
> >  ?column?
> > ----------
> >  f
> > (1 row)
> >
> > postgres=# select -1!=-1;
> > ERROR:  operator does not exist: integer !=- integer
> > LINE 1: select -1!=-1;
> >                  ^
> > HINT:  No operator matches the given name and argument types. You might
> > need
> > to add explicit type casts.
> > postgres=#

-- 
Erik





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


end of thread, other threads:[~2024-11-05 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-05 11:23 BUG #18689: psql : operator "!=" do not behave like "<>" PG Bug reporting form <noreply@postgresql.org>
2024-11-05 13:02 ` Rafia Sabih <rafia.pghackers@gmail.com>
2024-11-05 14:56   ` Tom Lane <tgl@sss.pgh.pa.us>
2024-11-05 15:05   ` Erik Wienhold <ewie@ewie.name>

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