Passing composite values to functions

From: "Jatinder Sangha" <Jatinder(at)sanghaservices(dot)co(dot)uk>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Passing composite values to functions
Date: 2004-02-13 15:24:48
Message-ID: VPOP31.5.0g.20040213152448.234.3.1.c2afae49@sanghapc1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-02-13 15:27:27 Re: 7.4 - FK constraint performance
Previous Message Tom Lane 2004-02-13 15:15:31 Re: column alias and group by/having/order