pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Clark Evans <clark.evans@manhattanproject.com>
To: Eduardo Noeda <enoeda@virtualsw.es>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] IIF..
Date: Mon, 29 Mar 1999 21:34:08 +0000
Message-ID: <36FFF1D0.FB1986CA@manhattanproject.com> (raw)
References: <199903291249190210.00CEB3B9@mail.virtualsw.es>

Eduardo Noeda wrote:
> function like SQL Server's "iif" in a SELECT query. 

Try this...

--------------------------------

--
-- Drop the iff function if it exists
--
DROP FUNCTION iff(bool,text,text);

--
-- Install procedural language, if it is not already
-- installed.  You may have to change the shared library
-- location to match your installation.
--
CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
'/opt/pgsql/lib/plpgsql.so' LANGUAGE 'C';

CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
   HANDLER plpgsql_call_handler
   LANCOMPILER 'PL/pgSQL';
  
--
-- Create the IFF function
--
create function iff(bool,text,text) RETURNS text AS '
   BEGIN
      IF $1 = true THEN
         RETURN $2;
      ELSE
         RETURN $3;
      END IF;
   END;
' LANGUAGE 'plpgsql';

--
-- Simple test plan.  
--

SELECT iff( 1 = 1, 'YEP', 'NOPE' );
SELECT iff( 1 = 0, 'YEP', 'NOPE' );

SELECT iff( 'x'::text = 'y'::text , 'YEP', 'NOPE' );
SELECT iff( 'x'::text = 'x'::text , 'YEP', 'NOPE' );



view thread (5+ messages)  latest in thread

Message-ID: <36FFF1D0.FB1986CA@manhattanproject.com>
Permalink:  ../36FFF1D0.FB1986CA@manhattanproject.com/
Also on:    postgresql.org/message-id/36FFF1D0.FB1986CA@manhattanproject.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: clark.evans@manhattanproject.com, enoeda@virtualsw.es
  Subject: Re: [SQL] IIF..
  In-Reply-To: <36FFF1D0.FB1986CA@manhattanproject.com>
  References: <199903291249190210.00CEB3B9@mail.virtualsw.es> <36FFF1D0.FB1986CA@manhattanproject.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