plpgsql rowtype
plpgsql rowtype
От:
Heiko.Kehlenbrink@vermes.fh-oldenburg.de
Дата:
hi all, i want to proof if if a rowtype has an attribute or get all attribute of a rowtype. like: CREATE OR REPLACE FUNCTION "test"() RETURNS varchar AS ' DECLARE rs_refr_row rs_refr%ROWTYPE; begin if ( proofing if rs_feat_row.id exists ) then select 1 into rs_feat_row.id; end if; RETURN rs_feat_row.id::varchar ; end; ' LANGUAGE 'plpgsql' best regards heiko kehlenbrink
Re: plpgsql rowtype
От:
Hubert Lubaczewski <hubert.lubaczewski@eo.pl>
Дата:
On Thu, 26 Jun 2003 11:47:47 +0200 (CEST) Heiko.Kehlenbrink@vermes.fh-oldenburg.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. depesz
Re: plpgsql rowtype
От:
Rory Campbell-Lange <rory@campbell-lange.net>
Дата:
On 30/06/03, Hubert Lubaczewski (hubert.lubaczewski@eo.pl) wrote:
> On Thu, 26 Jun 2003 11:47:47 +0200 (CEST)
> Heiko.Kehlenbrink@vermes.fh-oldenburg.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