pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ismail Kizir <ikizir@simteks.com.tr>
To: pgsql-sql@postgreSQL.org
Subject: PL/PgSql documentation and examples
Date: Wed, 29 Sep 1999 23:11:41 +0300
Message-ID: <006101bf0ab7$3b3e6120$a300aec3@kaplan> (raw)

Hi all,

I need more information and examples for pl/pgsql.
The examples found on the source tree of postgres are not sufficient,
because they are all alphanumerical examples. I need function examples for
numerical computations.
I tried to code the example below but it responded with error message
something like '$= operator not defined for types int4 and float8 ...'

Thanks in advance.
Ismail Kizir

CREATE FUNCTION fCurr (date, int2, float8, int2) RETURNS float8  AS '
  DECLARE
       fcDate ALIAS FOR $1;        -- Conversion date
       fromCurrID ALIAS FOR $2;  -- Which currency to convert
       Amount ALIAS FOR $3;       -- Amount to convert
       toCurrID ALIAS FOR $4;      -- Convert to which currency?
       BolenCarpan float8;
       BolunenCarpan float8;
  BEGIN
     IF fromCurrID = toCurrID THEN
       RETURN Amount; -- If source and destination are the same, the result
is the input amount
    END IF;

    IF fromCurrID = 1 THEN  -- If we convert the national currency
      BolunenCarpan = 1;
    ELSE
       SELECT Rate FROM CurrDaily INTO BolunenCarpan WHERE cDATE = fcDate
AND CurrID::int2=fromCurrID::int2;
       IF NOT FOUND THEN
          RAISE EXCEPTION ''Currency info for % #%d not
found'',fcDate,fromCurrID
       END IF;
    END IF;

     IF toCurrID = 1 THEN  -- If we convert to national currency
        BolenCarpan = 1;
    ELSE
        SELECT Rate FROM CurrDaily INTO BolenCarpan WHERE cDATE = fcDate AND
CurrID::int2=toCurrID::int2;
        IF NOT FOUND THEN
          RAISE EXCEPTION ''Currency info for % #%d not
found'',fcDate,fromCurrID
        END IF;
    END IF;
    RETURN Amount*BolunenCarpan/BolenCarpan;
 END;
' LANGUAGE 'plpgsql';




Message-ID: <006101bf0ab7$3b3e6120$a300aec3@kaplan>
Permalink:  ../006101bf0ab7$3b3e6120$a300aec3@kaplan/
Also on:    postgresql.org/message-id/006101bf0ab7$3b3e6120$a300aec3@kaplan

 · 

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: ikizir@simteks.com.tr
  Subject: Re: PL/PgSql documentation and examples
  In-Reply-To: <006101bf0ab7$3b3e6120$a300aec3@kaplan>
  References: <006101bf0ab7$3b3e6120$a300aec3@kaplan>

* 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