Re: $1 IS NULL with unknown type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: $1 IS NULL with unknown type
Date: 2022-11-21 20:02:45
Message-ID: 3263809.1669060965@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> writes:
> The operator `IS NULL` doesn't work if the argument has unknown type.
> conn.execute("select %s is null", ['foo']).fetchone()
> IndeterminateDatatype: could not determine data type of parameter $1

Yeah.

> It doesn't seem necessary to specify a type for an argument if it only
> has to be compared with null: nullness is independent from the type
> and is even specified, in the query parameters, in a separate array
> from the parameter values.

True, the IS NULL operator itself doesn't care about the data type,
but that doesn't mean that noplace else in the system does.

As an example, if we silently resolved the type as "text" as you seem
to wish, and then the client sends a non-null integer in binary format,
we'll likely end up throwing a bad-encoding error.

Maybe that's not a big problem, I dunno. But we can't just not
resolve the type, we have to pick something.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2022-11-21 20:12:04 Re: Cleanup: Duplicated, misplaced comment in HeapScanDescData
Previous Message Andres Freund 2022-11-21 19:56:28 Re: pgsql: Prevent instability in contrib/pageinspect's regression test.