Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Re: [INTERFACES] Odbc parser error

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: pgsql-interfaces(at)postgreSQL(dot)org, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: [INTERFACES] Odbc parser error
Date: 1998-09-21 23:41:03
Message-ID: v04011700b22c8ec8b8ff@[] (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-interfaces
Byron Nikolaidis <byronn(at)insightdist(dot)com> wrote:

> Yes, the NULL works for parameters of an update statement, where Access would
> specify a statement such as "update table set param = ? where x = 1".  But
> it doesn't work in a select statement.  I don't think I have much to work
> with here.  The statement comes in as something like "select * from table
> where x = ?".  I have to replace the ? with something.  On updates, 'NULL'
> works fine.
> I'm not sure what to do about this.  On other dbms, parameter passing is
> handled through a separate protocol to the backend, usually after a prepare
> statement, so on these its no problem to send a null, or large amounts of
> ascii/binary data, without having to worry about direct substitution into
> the sql string or hitting the upper limit of the statement string.  I think
> until Postgres has such as protocol for parameter substitution/passing, it
> will be difficult to fix this problem.

Well, before we jump high, I think this stems from a long-standing Postgres
problem - which I mentioned in the past, and I guess I'll continue to
mention, until we finally buy Oracle (and get a whole different set of

The problem is that in Postgres, NULL=NULL gives false.

As simple as that.

I am appaled to hear that this is still the situation. I thought by 6.4 (I
only have 6.2.1), the problem would probably be looked into, but I guess it

This NULL=NULL is FALSE problem explains why there is no problem in updates
(where the semantics of "=" is assignment, not comparison!).

The problem causes many other problems - like the inability to sort by two
fields when the first field may contain nulls. Why? Because sorting by two
fields means that when the values of the first fields in two rows are
compared and found equal, the second field is used for the comparison. But
if nulls are allowed, two rows with NULL in the first field are not
considered to have the same value! So, despite the nulls being sort of
"grouped together", their secondary sort fields will come out with an
arbitrary order!

This problem stems from Postgres's global definition that when you have

   operand1 operator operand2

and operand1 or operand2 are null, the result will always be NULL. That's
nice when you are trying to add 5 to a column, and expect all places where
there was NULL before to stay NULL, because NULL signifies "no data here".

Since the comparison operator is just an operator, the result of the
comparison is not really FALSE, but NULL. NULL, however, is interpreted
almost as a "false". To show this, here is an example of comparison:

testing=> create table test6 (val int);
testing=> copy test6 from stdin;
Enter info followed by a newline
End with a backslash and a period on a line by itself.
>> 1
>> 2
>> \N
>> 4
>> \.
testing=> select ( val = 2 ) from test6;

(4 rows)

By the way, the reason that I said "almost" is that the NOT boolean
operator, just like the binary operators I've discussed, returns NULL when
applied to NULL. Which means that NOT ( NULL = something ) will give you
the same result as NULL = something...

testing=> select ( val ) from test6 where NOT ( val = 2 );
(2 rows)

In short, something needs to be done about the semantics of the equality
operator. It should be treated as a special case - in order to maintain the
logic of logic, as well...

Suggested semantics:

Perhaps the general solution is always to treat NULLS as false in boolean
context, and have the equality operator return TRUE in the case where both
its operands are NULL.

Herouth Maoz, B.Sc.                Work:      herouth(at)oumail(dot)openu(dot)ac(dot)il
                                   Home:       herutma(at)telem(dot)openu(dot)ac(dot)il
HOME PAGE:                  
Internet technical assistant              Open University, Telem Project

In response to

pgsql-hackers by date

Next:From: The Hermit HackerDate: 1998-09-22 00:42:37
Subject: Re: [ Re: [HACKERS] BUG: NOT boolfield kills backend]
Previous:From: Brook MilliganDate: 1998-09-21 20:42:35
Subject: regress[ion].* files?

pgsql-interfaces by date

Next:From: Nelson Ferreira JuniorDate: 1998-09-22 18:49:54
Subject: My script doen't do INSERTs
Previous:From: REDCYT - Juan Carlos LiendroDate: 1998-09-21 21:56:06
Subject: java-postgresql

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group