From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | SHARMILA JOTHIRAJAH <sharmi_jo(at)yahoo(dot)com> |
Cc: | General postgres mailing list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Function that returns Boolean |
Date: | 2009-02-23 19:02:32 |
Message-ID: | 20090223190232.GA27811@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Feb 23, 2009 at 09:39:01AM -0800, SHARMILA JOTHIRAJAH wrote:
> Hi,
> This is a simple function that returns a boolean ..
This should be an SQL function, as it doesn't do anything you need (or
would even find convenient) for a more procedural language to do:
CREATE OR REPLACE FUNCTION check_value(newValue TEXT, oldValue TEXT)
RETURNS BOOLEAN
LANGUAGE SQL
AS $$ SELECT $1 IS DISTINCT FROM $2 $$;
As others have pointed out, IS DISTINCT FROM covers the case where one
or more of the arguments is a NULL.
Cheers,
David.
>
> create or replace function check_value( newValue IN VARCHAR,
> oldValue IN VARCHAR ) RETURN BOOLEAN
> as
> '
> BEGIN
> IF ( newValue != oldValue)
> then return true;
> else
> return false;
> END IF;
> END;
> '
> LANGUAGE 'plpgsql'
>
> But I get this error...what is wrong with this ?
>
> [Error] Script lines: 1-13 -------------------------
> ERROR: syntax error at or near "RETURN"
> Line: 2
>
> Thanks
> Sharmila
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-02-23 19:03:13 | Re: Product Roadmap question and request for recommendation |
Previous Message | Dot Yet | 2009-02-23 18:20:25 | Re: Product Roadmap question and request for recommendation |