Passing a ROWTYPE to a function - Mailing list pgsql-general

From Eric Brown
Subject Passing a ROWTYPE to a function
Date
Msg-id 465E9981-5F1A-11D9-8D7D-000A95C7176C@propel.com
Whole thread Raw
Responses Re: Passing a ROWTYPE to a function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Passing a ROWTYPE to a function  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
I'm trying to write a function that takes a %ROWTYPE as an argument.
I'm just not sure how to call it from another function.

This is what I tried:

<fixed><fontfamily><param>Courier New</param>CREATE TABLE t1 (x int, y
int);

INSERT INTO t1 VALUES (1, 2);

CREATE OR REPLACE FUNCTION g1(t1) RETURNS int LANGUAGE plpgsql AS '

BEGIN

    RETURN $1.y;

END';


CREATE OR REPLACE FUNCTION g2(int) RETURNS int LANGUAGE plpgsql AS '

DECLARE item t1%ROWTYPE;

BEGIN

    SELECT INTO item * FROM t1 WHERE x = $1;

    RETURN g1(item);

END';


SELECT g2(1);

</fontfamily></fixed>

This is what I got:

<fixed><fontfamily><param>Courier New</param>CREATE TABLE

INSERT 28089 1

CREATE FUNCTION

CREATE FUNCTION

psql:/tmp/test.sql:16: ERROR:  column "item" does not exist

CONTEXT:  PL/pgSQL function "g2" line 4 at return

</fontfamily></fixed>


I'm using posgresql 7.4.6.


Thanks.


Eric Brown

408-571-6341

www.propel.com
I'm trying to write a function that takes a %ROWTYPE as an argument.
I'm just not sure how to call it from another function.
This is what I tried:
CREATE TABLE t1 (x int, y int);
INSERT INTO t1 VALUES (1, 2);
CREATE OR REPLACE FUNCTION g1(t1) RETURNS int LANGUAGE plpgsql AS '
BEGIN
     RETURN $1.y;
END';

CREATE OR REPLACE FUNCTION g2(int) RETURNS int LANGUAGE plpgsql AS '
DECLARE item t1%ROWTYPE;
BEGIN
     SELECT INTO item * FROM t1 WHERE x = $1;
     RETURN g1(item);
END';

SELECT g2(1);

This is what I got:
CREATE TABLE
INSERT 28089 1
CREATE FUNCTION
CREATE FUNCTION
psql:/tmp/test.sql:16: ERROR:  column "item" does not exist
CONTEXT:  PL/pgSQL function "g2" line 4 at return


I'm using posgresql 7.4.6.

Thanks.

Eric Brown
408-571-6341
www.propel.com

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: PostgreSQL users on webhosting
Next
From: Alan Garrison
Date:
Subject: Re: PostgreSQL users on webhosting