Re: Function and RowType

From: Carlos Roberto Chamorro Mostacilla <carlosrchamorro(at)yahoo(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Function and RowType
Date: 2004-07-14 13:14:47
Message-ID: 20040714131447.85185.qmail@web41415.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Working with 7.4.3

CREATE TABLE a_preuba (
codigo varchar(2) not null,
descripcion varchar(250) not null,
valor integer,
hora date
);

Function that constructs and returns rowtype:
CREATE OR REPLACE FUNCTION retornar_record(VARCHAR)
RETURNS a_prueba AS '
DECLARE
retorno a_prueba%rowtype;
sbestacodi alias for $1;
BEGIN
SELECT INTO retorno * FROM a_prueba where codigo
= sbestacodi ;
RETURN retorno;
END;
' LANGUAGE plpgsql;

Function that receives rowtype and writes its content
:
CREATE OR REPLACE FUNCTION probar_record(a_prueba)
RETURNS varchar AS '
DECLARE
registro ALIAS FOR $1;
BEGIN
RAISE NOTICE '' Código : % Descripción : % Valor :
% '',
registro.codigo,registro.descripcion,
registro.valor;
RETURN registro.descripcion;
END;
' LANGUAGE plpgsql;

Use of the functions :
1. CREATE OR REPLACE FUNCTION probar()
2. RETURNS text AS'
3. DECLARE
4. reg a_prueba%ROWTYPE;
5. BEGIN
--To initialize a ROWTYPE
6. SELECT * INTO reg FROM retornar_record(''06'');
7. reg.codigo := ''99'';

-- It works within a consultation
8. PERFORM probar_record(t.*)
from a_prueba t
where codigo = ''06'';

-- It works with a function that returns
rowtype
--Directly
9. PERFORM
probar_record(retornar_record(''01''));

--IT DOES NOT WORK
10. PERFORM probar_record(reg);

11. RETURN NULL;
12. END;
13. ' LANGUAGE plpgsql;

If you observe in line 6 and 7 I initialize rowtype
and I modify it but in 10, line treatment to pass it
to the function and says to me that reg is not a
column; The calls in line 8 and 9 funciónan, i find
in some forums and probe but I have not been able to
find nothing for line 10, because I need to modify
rowtype before passing it. Some idea?

_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message pdvluca 2004-07-14 14:08:12 Triggers called twice, triggers debugging
Previous Message David Helgason 2004-07-14 11:38:36 Re: