Re: Minor difference in behavior between +/- - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: Minor difference in behavior between +/-
Date
Msg-id CAKFQuwZpDPkgwX8J46H23hYzN9ezdT5W3cQZA9z5rJgFVOSPjA@mail.gmail.com
Whole thread Raw
In response to Minor difference in behavior between +/-  (Ryan Murphy <ryanmurf@gmail.com>)
Responses Re: Minor difference in behavior between +/-  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List pgsql-bugs


On Tuesday, January 24, 2023, Ryan Murphy <ryanmurf@gmail.com> wrote:
SELECT NULL - date '2023-01-05';
-> result is null
SELECT NULL + date '2023-01-05';
-> result is [42725] ERROR: operator is not unique: unknown + date Hint: Could not choose a best candidate operator. You might need to add explicit type casts. Position: 13


There is no bug here.
 
I would expect both of those to be null.

I get why you expect that but we expend little to no effort to handle null in a type agnostic way.  Type inference has to happen first and regardless of whether the literal is null.  Type inference failed in the + case but not the - case.  That is just happenstance of what operators happen to exist in the system.

David J.

pgsql-bugs by date:

Previous
From: Peter Bex
Date:
Subject: Re: Unique constraint error instead of serialization_failure
Next
From: Dean Rasheed
Date:
Subject: Re: BUG #17759: MERGE UPDATE statements do not cause generated columns to update