Passing composite values to functions - Mailing list pgsql-sql

From Jatinder Sangha
Subject Passing composite values to functions
Date
Msg-id VPOP31.5.0g.20040213152448.234.3.1.c2afae49@sanghapc1
Whole thread Raw
Responses Re: Passing composite values to functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi,
 
I'm having trouble passing a composite variable to a function.
 
I have a composite as follows:
 
    declare userRecord dnaUsers%ROWTYPE;
 
and I manipulate it like this:
 
    select into userRecord * from dnaUsers where etc;
    userRecord.userid := 'jatinder'; --etc
 
 
I would like to then insert this record into the table (kind of like this):
 
    insert into dnaUsers select userRecord;
    insert into dnaUsers select userRecord.*;
    insert into dnaUsers values (userRecord);
    insert into dnaUsers values (userRecord.*);
 
All of the above generate various errors relating to "userRecord" not being a table?
 
I can't find any examples of this in the archives or the documentation. Is this even possible?
 
I also, haven't found a way to pass my "userRecord" to a function, eg:
 
create or replace function isUserActive (dnaUsers)
returns boolean
as '
    do something with $1;
    return true;
' language plpgsql;

The problem here is that I can't pass userRecord to the new function:
 
    isActive := isUserActive (userRecord);
 
Again, the errors appear to be about "userRecord" not being a table?
 
So, is it even possible to use composite records in this manner? All of the examples I've seen, seem to be about passing a row of a direct select statement as a composite argument to a function, and not about passing a locally declared composite variable.
 
Can anyone help correct my understanding of what I can and can't do with composites?
 
Thanks,
--Jatinder

pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: arrays and polygons
Next
From: Rod Taylor
Date:
Subject: Re: 7.4 - FK constraint performance