X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 529BFD1B522 for ; Thu, 13 Nov 2003 16:08:33 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 65004-03 for ; Thu, 13 Nov 2003 12:08:02 -0400 (AST) Received: from dyatel.antar.bryansk.ru (unknown [195.239.214.85]) by svr1.postgresql.org (Postfix) with ESMTP id 465CBD1B532 for ; Thu, 13 Nov 2003 12:08:02 -0400 (AST) Received: from fduch by dyatel.antar.bryansk.ru with local (Exim 4.24; FreeBSD) id 1AKK0m-000FSI-64 for pgsql-sql@postgresql.org; Thu, 13 Nov 2003 19:08:00 +0300 Date: Thu, 13 Nov 2003 19:08:00 +0300 From: "Alexander M. Pravking" To: pgsql-sql@postgresql.org Subject: STRICT function returning a composite type Message-ID: <20031113160800.GL69653@dyatel.antar.bryansk.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/155 X-Sequence-Number: 15970 I noted that such a function returns an empty rowset if a NULL value is passed as an argument. Is it a bug or feature? I wish it was a feature, because I probably want to use this behavour. Here's an example: CREATE TYPE ts_bounds AS ( sdate timestamptz, edate timestamptz ); CREATE OR REPLACE FUNCTION overlap_bounds(timestamptz, timestamptz, timestamptz, timestamptz) RETURNS ts_bounds AS ' DECLARE sdate1 ALIAS FOR $1; edate1 ALIAS FOR $2; sdate2 ALIAS FOR $3; edate2 ALIAS FOR $4; res ts_bounds%rowtype; BEGIN res.sdate := CASE WHEN sdate1 > sdate2 THEN sdate1 ELSE sdate2 END; res.edate := CASE WHEN edate1 < edate2 THEN edate1 ELSE edate2 END; IF res.sdate > res.edate THEN res.sdate := NULL; res.edate := NULL; END IF; RETURN res; END' LANGUAGE 'plPgSQL' STRICT; fduch=# SELECT * from overlap_bounds('-infinity', 'today', 'yesterday', 'infinity'); sdate | edate ------------------------+------------------------ 2003-11-12 00:00:00+03 | 2003-11-13 00:00:00+03 (1 row) fduch=# SELECT * from overlap_bounds('-infinity', 'today', 'yesterday', null); sdate | edate -------+------- (0 rows) What I want is to get no rows if given intervals don't overlap instead of: fduch=# SELECT * from overlap_bounds('-infinity', 'yesterday', 'today', 'infinity'); sdate | edate -------+------- | (1 row) Is it possible without returning SETOF ts_bounds? fduch=# SELECT version(); version --------------------------------------------------------------------- PostgreSQL 7.3.4 on i386-portbld-freebsd4.8, compiled by GCC 2.95.4 -- Fduch M. Pravking