Differentiate Between Zero-Length String and NULL Column Values

From: "Phillip Smith" <phillip(dot)smith(at)weatherbeeta(dot)com(dot)au>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Differentiate Between Zero-Length String and NULL Column Values
Date: 2007-01-30 05:32:22
Message-ID: 016d01c74430$043b1b90$9b0014ac@wbaus090
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi All,

Small problem with 8.2.1, I have a temp table of basic stock details:
CREATE TEMP TABLE tmpstk
(
code varchar(6),
description varchar(38),
grp varchar(4),
brand text,
style text,
supplier varchar(6),
supplier_code text,
wholesale numeric(10,2),
retail numeric(10,2),
ean varchar(13)
)
WITHOUT OIDS;

This table is populated using a COPY query – works OK. If I try the
following query:
SELECT * FROM tmpstk
I get what I expect, almost 8000 rows including rows similar to the
following:
"401514","EQUINADE_SHOWSILK_SHAMPOO_5L","3209","EQUINADE","SHAMPOO","EQUEST"
,"401514","0.00","0.00","0.00","0.00","10.00","9329028056594"
"401600","A/DRESS_SHAMPOO_TEA_TREE_OIL_500ML","3208","AUSTRALIAN_DRESSAGE","
SHAMPOO","EQUEST","401600","0.00","0.00","0.00","0.00","10.00",""

The second row (401600) is what I’m interested in for this particular
problem. The problem is when I try and add a WHERE clause:
SELECT * FROM tmpstk WHERE ean = '';
SELECT * FROM tmpstk WHERE TRIM(ean) = '';
SELECT * FROM tmpstk WHERE ean = NULL;
None of the above queries return any rows.

What am I doing wrong? It should return the 401600 row above, along with
several hundred other rows. I have attached the bash script that actually
does this processing.

Help is much appreciated.
Cheers,
-p

Phillip Smith
IT Coordinator
Weatherbeeta P/L
AUSTRALIA
 
E. phillip(dot)smith(at)NO-SPAM(dot)weatherbeeta(dot)com(dot)au

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

Attachment Content-Type Size
import-wb-stock.sh application/x-sh 2.3 KB

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2007-01-30 05:45:43 Re: Differentiate Between Zero-Length String and NULL Column Values
Previous Message Bruce Momjian 2007-01-29 21:02:07 Re: [ADMIN] server process (PID xxx) was