PLpgSQL-Problem

Started by Thomas Chillealmost 22 years ago6 messagesgeneral
Jump to latest
#1Thomas Chille
thomas@chille.de

Hi,

i am playing around with PLpgSQL and can not solve one problem: I am fetching some rows of a special rowtype and wanna give this
rows step by step to a function with this rowtype as parameter.

evertime i get the errormessage: ERROR: Attribut �_row� not found

but the Attribut exists and has values in his fields. i have absolutly no idea was happens there. can someone help me please?

thanx
thomas

-------snip function 1

CREATE OR REPLACE FUNCTION "public"."compress_main" (date) RETURNS boolean AS'
DECLARE
_day ALIAS FOR $1;
_row public.tmp_order_data%ROWTYPE;
_result boolean;
eb bigint;
BEGIN

DELETE FROM hlp_operator WHERE selling_date = _day;

FOR _row IN
SELECT * FROM tmp_order_data WHERE business_day = _day ORDER BY transactiontime
LOOP
IF _row.id_transactiontype = 100 THEN
SELECT INTO _result compress_100(_row);
END IF;
END LOOP;

RETURN TRUE;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

-------snip function 2:

CREATE OR REPLACE FUNCTION "public"."compress_100" ("public"."tmp_order_data") RETURNS boolean AS'
DECLARE
_record ALIAS FOR $1;
_shift int8;
BEGIN

/* any code */

RETURN TRUE;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Chille (#1)
Re: PLpgSQL-Problem

"Thomas Chille" <thomas@chille.de> writes:

evertime i get the errormessage: ERROR: Attribut �_row� not found
but the Attribut exists and has values in his fields. i have absolutly no idea was happens there. can someone help me please?

You're out of luck :-( ... plpgsql doesn't presently have the ability to
pass a whole-row value to the main executor, which means this won't
work:

SELECT INTO _result compress_100(_row);

Possibly it will work in 7.5; I've made some preliminary steps in that
direction but it's not all there yet.

regards, tom lane

#3Thomas Chille
thomas@chille.de
In reply to: Thomas Chille (#1)
Re: PLpgSQL-Problem

Hello Tom,

thank u for your fast reply!

Now I understand that i can not split easily my scripts into logical units but what i not understand is the documention not correct
or is my problem not similiar to the example in point 37.4.3 on http://www.postgresql.org/docs/7.4/static/plpgsql-declarations.html
?

thank u for your help,
thomas

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Chille (#3)
Re: PLpgSQL-Problem

"Thomas Chille" <thomas@chille.de> writes:

Now I understand that i can not split easily my scripts into logical units but what i not understand is the documention not correct
or is my problem not similiar to the example in point 37.4.3 on http://www.postgresql.org/docs/7.4/static/plpgsql-declarations.html
?

It is, but the only sort of operation you can apply to a row variable in
plpgsql is to extract a field from it. Other operations like calling a
function on it don't work (yet).

regards, tom lane

#5Thomas Chille
thomas@chille.de
In reply to: Thomas Chille (#1)
Re: PLpgSQL-Problem

Hi Tom,

sorry for asking again on the same issue but i try to figure out how i have to deal with and how strong i can trust the
postgres-docs and -books.

in every documentation(7.5 too) i can read that i can pass a row to a plpgsql function. but how u know it does not work. i am still
thinking i am wrong or are really all that docs wrong?

And if the documentation is wrong, is this normal for the postgres-docs?

I dont wanna steal your time, but i can not understand it.

regards
thomas

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Chille (#5)
Re: PLpgSQL-Problem

"Thomas Chille" <thomas@chille.de> writes:

in every documentation(7.5 too) i can read that i can pass a row to a
plpgsql function. but how u know it does not work.

It does work ... from a SQL statement. The problem you are running into
is that a whole-row variable of a plpgsql function can't be passed as a
unit into a SQL statement. (I thought this limitation was documented
somewhere in the plpgsql chapter, but right at the moment I can't find
anything about it.)

And if the documentation is wrong, is this normal for the postgres-docs?

The documentation is not perfect.

regards, tom lane