Passing a ROWTYPE to a function

From: Eric Brown <eric(dot)brown(at)propel(dot)com>
To: PgSQL General List <pgsql-general(at)postgresql(dot)org>
Subject: Passing a ROWTYPE to a function
Date: 2005-01-05 13:04:03
Message-ID: 465E9981-5F1A-11D9-8D7D-000A95C7176C@propel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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:
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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mage 2005-01-05 14:35:22 multi column index and order by
Previous Message Jeff Davis 2005-01-05 08:17:41 Re: PostgreSQL users on webhosting