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