Help with "empty()"

From: Alan Wayne <alanjwayne(at)yahoo(dot)com>
To: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>, Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Help with "empty()"
Date: 2002-05-24 03:57:25
Message-ID: 20020524035725.69969.qmail@web21210.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

In doing table validation, I have often used the
foxpro function "empty()" which returns .t. if the
enclosed entity is empty. i.e., if boolean .f. then
empty = .t.. If number 0, then empty = .t., and if a
blank string, then empty = .t.

I didn't see anyother way to mimic this behavior then
what I wrote below, is there a better way????

Please help, suggestions are appreciated!
Cheers,
ajw

CREATE FUNCTION zzipcode_validate_fields() RETURNS
opaque AS '
BEGIN
IF NEW.izipcode ISNULL THEN
RAISE EXCEPTION ''zipcode is null.'' ;
ELSE
IF char_length( trim(both from NEW.izipcode)) < 9
THEN
RAISE EXCEPTION ''zipcode less-then 9-digits.'' ;
END IF;
END IF;

IF NEW.cstate ISNULL THEN
RAISE EXCEPTION ''state is null.'' ;
ELSE
IF char_length( trim(both from NEW.cstate))=0 THEN
RAISE EXCEPTION ''state is empty string.'';
END IF;
END IF;

IF NEW.ccity ISNULL THEN
RAISE EXCEPTION ''city is null.'';
ELSE
IF char_length( trim(both from NEW.ccity)) = 0
THEN
RAISE EXCEPTION ''city is empty string.'' ;
END IF;
END IF;

NEW.cstate := upper(NEW.cstate);
NEW.ccity := upper(NEW.ccity);
RETURN NEW;
END;
'LANGUAGE 'plpgsql';

CREATE TRIGGER zzipcode_validate BEFORE INSERT OR
UPDATE ON zzipcode
FOR EACH ROW EXECUTE PROCEDURE
zzipcode_validate_fields();

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-05-24 04:14:50 Re: Help with "empty()"
Previous Message Glen Parker 2002-05-24 01:17:18 Pg_dump and huge OID's