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

Re: [INTERFACES] selectecting not null varchars.

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
Cc: Joseph Shraibman <jks(at)p1(dot)selectacast(dot)net>, "pgsql-interfaces(at)postgreSQL(dot)org" <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: Re: [INTERFACES] selectecting not null varchars.
Date: 2000-02-24 20:40:06
Message-ID: 20000224144006.B11186@rice.edu (view raw or flat)
Thread:
Lists: pgsql-interfaces
On Thu, Feb 24, 2000 at 02:04:40PM -0600, Ed Loehr wrote:
> Joseph Shraibman wrote:
> > 
> >  select * from directory where h != null  ;
> > ... gets you this:
> > ERROR:  parser: parse error at or near ";"
> 
> Postgresql's SQL "not equal" operator is "<>"...Try this:
> 
> 	select * from directory where h <> null;

Which is still throw an error.  and the SQL standard way to test for
NOT NULL is:

SELECT * FROM directory WHERE h IS NOT NULL;

Here's an example:

test=> \d test
Table    = test
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                | Length|
+----------------------------------+----------------------------------+-------+
| date                             | int4 default now ( )             |     4 |
| t                                | text                             |   var |
+----------------------------------+----------------------------------+-------+
test=> insert into test (t) values ('');
INSERT 869922 1
test=> select * from test;
     date|t    
---------+-----
949357548|two  
949357551|later
951424534|     
       -1|one  
951424715|     
(5 rows)

test=> select * from test where t is not null;
     date|t    
---------+-----
949357548|two  
949357551|later
       -1|one  
951424715|     
(4 rows)

test=> 

test=> select * from test where length(t) >0;
ERROR:  Null input to textlen

test=> select * from test where t is not null and length(t) >0;
     date|t    
---------+-----
949357548|two  
949357551|later
       -1|one  
(3 rows)

test=> 

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005

In response to

Responses

pgsql-interfaces by date

Next:From: Joseph ShraibmanDate: 2000-02-24 21:46:47
Subject: Re: [INTERFACES] selectecting not null varchars.
Previous:From: Ed LoehrDate: 2000-02-24 20:04:40
Subject: Re: [INTERFACES] selectecting not null varchars.

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