Re: PL/PGSQL rowtype return pr

From: rwickert(at)contextworld(dot)com
To: pavel(dot)stehule(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/PGSQL rowtype return pr
Date: 2007-06-12 14:02:51
Message-ID: 4EF2E006BE.01DC005FTFSFSBZS@contextworld.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

Yes that works but when I try to put the results of a rowtype returning function into a rowtype variable in another function i cannot access the individual attributes from variable. Only from the direct call.

ie.

x1 := (get_defaults_vals()).a1
x2 := (get_defaults_vals()).a2
x3 := (get_defaults_vals()).a3

i can't do

declare
vals default_vals%rowtype
begin
select get_defaults_vals() into vals;

x1 := default_vals.a1;

I can't do this. Postgresql seems to forget what the attributes are if i put the results into a rowtype variable.

-----Original Message-----
From: pavel(dot)stehule(at)gmail(dot)com
Sent: 12 June 2007 13:49
To: Robert Wickert
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] PL/PGSQL rowtype return pr

-------------------------------------------------------------------------- --
Hello,

my code works well:

CREATE TABLE Foo(a integer, b integer);

CREATE OR REPLACE FUNCTION ret_foo()
RETURNS Foo AS $$
DECLARE r Foo;
BEGIN
r := (10,20); --default
RETURN r;
END; $$
LANGUAGE plpgsql;

SELECT ret_foo();

CREATE OR REPLACE FUNCTION trig()
RETURNS TRIGGER AS $$
BEGIN
NEW := ret_foo();
RETURN NEW;
END; $$
LANGUAGE plpgsql;

CREATE TRIGGER footrig BEFORE INSERT ON Foo
FOR EACH ROW EXECUTE PROCEDURE trig();

INSERT INTO Foo VALUES(0,0);

Regards
Pavel Stehule

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/
*****************************************************
Robert Wickert
Senior Software Developer
CONTEXT
Tel:+44 (0)20 8394 7739
Fax:+44 (0)20 8394 7701
Email Address: rwickert(at)contextworld(dot)com
Web Site: http://www.contextworld.com
*****************************************************
This message and the information contained therein is intended for the use
of the person(s) ("the intended recipient(s)" to whom it is addressed. It
may contain information that is privileged and confidential within the
meaning of applicable law. If you are not the intended recipient, please
contact the sender as soon possible. The views expressed in this
communication may not necessarily be the views held by Context or its
subsidiaries. The contents of an attachment to this e-mail may contain
viruses that could damage your own computer system. While every reasonable
precaution has been taken to minimise this risk, Context and its
subsidiaries cannot accept liability for any damage which you sustain as a
result of software viruses. You should carry out your own virus checks
before opening the attachment. Please notice that Context monitors e-mails
sent or received. Further communication will signify your consent to this.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vincenzo Romano 2007-06-12 14:18:32 INSERT ... RETURNING in v8.2
Previous Message Kevin Hunter 2007-06-12 13:07:57 Re: Suppress checking of chmod 700 on data-dir?