Re: [SQL] Letting a function work on NULL

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Anton de Wet <adw(at)obsidian(dot)co(dot)za>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Letting a function work on NULL
Date: 1999-06-21 10:57:31
Message-ID: l03130302b393b9495dc4@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 21:53 +0300 on 20/06/1999, Anton de Wet wrote:

> But all gives:
>
> select ym(NULL);
> ERROR: typeidTypeRelid: Invalid type - oid = 0
>
> Is there any way to specify an exception on the input type?

There are two different issues here. First, passing the "literal" NULL to
functions always results in this. In SQL92, NULL is not even considered a
literal. Try this, for example:

testing=> select abstime( NULL ) from test2;
ERROR: typeidTypeRelid: Invalid type - oid = 0

(abstime() is a builting function converting to abstime);

In order to test the functionality of a function in nulls, you should
create a table, some of whose values are null:

testing=> select f, abstime( f ) from test2;
f|abstime
------------+----------------------------
3.1415926535|Sat Jan 01 02:00:03 2000 IST
|
1.11111|Sat Jan 01 02:00:01 2000 IST
(3 rows)

That's about your testing procedure. About your problem in itself: you
should either use a pl/pgsql procedure or make use of COALESCE.

One last note: EXCEPT is a query operator that excludes certain tuples from
a query. It's not an "else". When you write "SELECT something1 EXCEPT
SELECT something2", it means "select all the 'something1' objects which are
not 'something2'

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message José Soares 1999-06-21 12:13:08 Re: [SQL] Letting a function work on NULL
Previous Message Anton de Wet 1999-06-20 18:53:53 Letting a function work on NULL