Re: plpgsql rowtype

From: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
To: Heiko(dot)Kehlenbrink(at)vermes(dot)fh-oldenburg(dot)de, pgsql-novice(at)postgresql(dot)org
Subject: Re: plpgsql rowtype
Date: 2003-06-30 13:39:53
Message-ID: 20030630133953.GA3628@campbell-lange.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 30/06/03, Hubert Lubaczewski (hubert(dot)lubaczewski(at)eo(dot)pl) wrote:
> On Thu, 26 Jun 2003 11:47:47 +0200 (CEST)
> Heiko(dot)Kehlenbrink(at)vermes(dot)fh-oldenburg(dot)de wrote:
>
> > i want to proof if if a rowtype has an attribute or get all
> > attribute of a rowtype.
>
> as far as i know - you can't. what would you need it for? do you need a proof for variable being of "text" type when declared as text?
> you declared it as rowtype - so it's rowtype.

Why don't you make a type with the fields you want. Set these to a
default value. Then check for whether or not a variable has been set the
way you want it. (See below). Otherwise maybe all you need is to declare
a record type and select into that, and then check the variables.

Hope this helps.
Rory

CREATE TYPE view_object as (
itemid VARCHAR,
itemtype INT2,
itemtitle VARCHAR
);

CREATE OR REPLACE FUNCTION fn_v3_object_view
(integer, varchar, integer) RETURNS view_object
AS '
DECLARE
boardid ALIAS for $1;
recone RECORD;
BEGIN
resulter.itemid := '''';
resulter.itemtype := 0;
resulter.itemtitle := '''';

SELECT INTO recone
itemid, itemtype, itemtitle
FROM
objects
WHERE
n_boardid = boardid;

IF NOT FOUND OR recone.itemid < 1 THEN
RAISE NOTICE ''my error message'';
RETURN resulter;
END IF;

resulter.itemid := recone.itemid;
resulter.itemtype := recone.itemtype;
resulter.itemtitle := recone.itemtitle;

RETURN resulter;

END;'
LANGUAGE plpgsql;
--
Rory Campbell-Lange
<rory(at)campbell-lange(dot)net>
<www.campbell-lange.net>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Chris Boget 2003-06-30 13:42:07 Re: Noobie: Problems with a query
Previous Message cristi 2003-06-30 13:36:30 blobs