pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Travers <chris@travelamericas.com>
To: Matt L. <survivedsushi@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: nullif('','') on insert
Date: Fri, 26 Aug 2005 23:45:25 -0700
Message-ID: <43100C05.7020309@travelamericas.com> (raw)
In-Reply-To: <20050821014023.92296.qmail@web35209.mail.mud.yahoo.com>
References: <20050821014023.92296.qmail@web35209.mail.mud.yahoo.com>

Matt L. wrote:

>I need to test whether or not a value is null on
>insert. 
>
>Example: insert into table (column) values
>nullif('',''));
>ERROR: column "column" is of type boolean but
>expression is of type text.
>  
>
Your problem is that NULL's are typed in PostgreSQL.

Try this:

SELECT NULL;
SELECT NULL::BOOL;
SELECT NULL::BOOL::TEXT;

to see what I mean.  This is an exact illustration of your problem.

>It works in MSSQL (probably against not standards) but
>nonetheless I need to make it work.
>
>I assume it's returning 'NULL' w/ quotes?
>
Nope.  It is returning a text string which is valued at NULL.  It cannot 
convert a text string to a BOOL (even if the string is a NULL) so it 
gives you an error.

> I don't know
>where to look to alter it. I looked into functions but
>all I see is how to write "AS queries" or point to
>various snippets. I'd rather just alter the nullif
>function. 
>  
>
SELECT NULLIF('' = '', TRUE);

Does this work?  You could write a wrapper function if necessary.....

Best Wishes,
Chris Travers
Metatron Technology Consulting



view thread (3+ messages)  latest in thread

Message-ID: <43100C05.7020309@travelamericas.com>
Permalink:  ../43100C05.7020309@travelamericas.com/
Also on:    postgresql.org/message-id/43100C05.7020309@travelamericas.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chris@travelamericas.com, survivedsushi@yahoo.com
  Subject: Re: nullif('','') on insert
  In-Reply-To: <43100C05.7020309@travelamericas.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox