pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Hunnisett <david.hunnisett@probit.io>
To: pgsql-bugs@lists.postgresql.org
Subject: differences between <> and != when using signed values on the right hand side
Date: Thu, 16 May 2024 10:27:25 +0100
Message-ID: <B9C40FC5-5FA1-40DF-BC91-114493622F61@probit.io> (raw)

When using a signed comparison != does not behave like <> if the right hand side comparator is signed and there is no space between the comparator and the sign

<>+1
<>-1 
Both bahave as the inverse to
=+1
=-1
But 
!=-1
!=+1
Throw errors.


Tested with 16.3,13.15 and 9.6.24


postgres=# select version();
                                                          version                                                          
---------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)

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

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

postgres=# select 1!=-1.0;
ERROR:  operator does not exist: integer !=- numeric
LINE 1: select 1!=-1.0;
                ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
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.

Adding a space does produce the expected answer

select 1!= -1.0;
 ?column? 
----------
 t
(1 row)

view thread (3+ messages)  latest in thread

Message-ID: <B9C40FC5-5FA1-40DF-BC91-114493622F61@probit.io>
Permalink:  ../B9C40FC5-5FA1-40DF-BC91-114493622F61@probit.io/
Also on:    postgresql.org/message-id/B9C40FC5-5FA1-40DF-BC91-114493622F61@probit.io

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: david.hunnisett@probit.io, pgsql-bugs@lists.postgresql.org
  Subject: Re: differences between <> and != when using signed values on the right hand side
  In-Reply-To: <B9C40FC5-5FA1-40DF-BC91-114493622F61@probit.io>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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