Re: new type question

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Sim Zacks <sim(at)compulab(dot)co(dot)il>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: new type question
Date: 2005-10-17 17:51:35
Message-ID: 20051017175135.GA86144@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Oct 16, 2005 at 11:03:52AM +0200, Sim Zacks wrote:
> create function uint_in(val cstring) returns uint2 as
> $$
> declare thisval int4;
> begin
> thisval=val::int4
> if thisval between 0 and 65535 then
> return (thisval-32768)::int2;
> else
> return 0;
> end if;
> end
> $$ language 'plpgsql';

On a side note, do you really want to punt to 0 when an invalid value
comes it? That sounds like something MySQL would do... ISTM you should
throw an error.

Also, you could have written that as a pure SQL function, which would
have been faster (assuming you could use something other than C for
this).
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Travers 2005-10-17 17:53:36 Re: Oracle buys Innobase
Previous Message Simon Riggs 2005-10-17 17:46:36 Re: [GENERAL] Oracle buys Innobase