From: Gary Chambers <gwchamb@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Function Anomaly?
Date: Wed, 7 Oct 2009 22:25:20 -0400
Message-ID: <302670f20910071925g30322072oc9395e83d592ad2b@mail.gmail.com> (raw)
All...
Given the following type and function:
CREATE TYPE getnote_t AS (nid BIGINT, ownerid INTEGER, ownername
VARCHAR, hostname VARCHAR,
entrytime TIMESTAMP, is_active VARCHAR, is_private VARCHAR, notetext TEXT);
CREATE OR REPLACE FUNCTION getnote(INTEGER, BIGINT) RETURNS getnote_t AS
$getnote$
SELECT n.nid AS nid, n.ownerid AS ownerid, o.ownername AS ownername,
n.hostname AS hostname,
n.entrytime::TIMESTAMP(0) AS entrytime,
'[' || (CASE WHEN n.is_private = TRUE THEN 'PRIVATE' ELSE 'SHARED'
END) || ']' AS is_private,
'[' || (CASE WHEN n.is_active = FALSE THEN 'INACTIVE' ELSE
'ACTIVE' END) || ']' AS is_active,
n.notetext AS notetext
FROM notes n, owners o
WHERE (CASE WHEN (n.ownerid != $1 AND n.is_private IS TRUE) THEN FALSE
ELSE TRUE END)
AND n.ownerid = o.ownerid AND n.nid = $2
$getnote$ LANGUAGE SQL;
When I call it with a row where n.is_private is TRUE and n.ownerid IS
TRUE, I receive a single row of all null values:
notesdb=# select * from getnote(1, 2);
nid | ownerid | ownername | hostname | entrytime | is_active |
is_private | notetext
-----+---------+-----------+----------+-----------+-----------+------------+----------
| | | | | | |
(1 row)
When I submit the query directly (getnote.sql is simply the query with
the CASE statement forced to false):
notesdb=# \i getnote.sql
nid | ownerid | ownername | hostname | entrytime | is_private |
is_active | notetext
-----+---------+-----------+----------+-----------+------------+-----------+----------
(0 rows)
Thanks very much in advance for any insight you can provide.
-- Gary Chambers
/* Nothing fancy and nothing Microsoft! */
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gwchamb@gmail.com
Subject: Re: Function Anomaly?
In-Reply-To: <302670f20910071925g30322072oc9395e83d592ad2b@mail.gmail.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