postgresql – Why can’t parameters be null or empty strings when compared in a SELECT in PG?


This is very strange. For a very long time, I’ve been INSERTing parameters into PG queries from PHP like this:

INSERT INTO table (column) VALUES ($1);

The $1 can be a boolean null or an empty string. Works perfectly.

Now, I’m “suddenly” getting errors, probably because I’ve never happened to encountered this situation before:

SELECT * FROM table WHERE column <> $1;

If $1 is either null or an empty string, I get:

pg_query(): Query failed: ERROR:  there is no parameter $1

At first, I thought it might be logically related to the <> operator, but this also gives the very same error:

SELECT * FROM table WHERE column = $1;

I have foggy memories of NULL being annoyingly “special case” in PG, but even empty strings? And why specifically for SELECTs but not INSERTs?