Function parameters of rowtype

Started by Iker Arizmendiabout 22 years ago4 messagesgeneral
Jump to latest
#1Iker Arizmendi
iker@research.att.com

How are function parameters of rowtype specified when
calling them from a client such as libpq? Is there a syntax
similar to that for arrays? (eg, {x, y, z} )

Thanks,
Iker

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Iker Arizmendi (#1)
Re: Function parameters of rowtype

Iker Arizmendi <iker@research.att.com> writes:

How are function parameters of rowtype specified when
calling them from a client such as libpq?

Something like
select myfunc(t.*) from tab t where ...

regards, tom lane

#3Iker Arizmendi
iker@research.att.com
In reply to: Tom Lane (#2)
Re: Function parameters of rowtype

But what if there is no table? Instead, is there
some way to specify the row tuple explicitly, similar
to what is done for arrays? I'd like to create a type
and define an instance of that type as part of the
SQL statement. For example,

CREATE TYPE user_t
{
id varchar,
pwd varchar
};

CREATE FUNCTION add_user(user_t)
RETURNS INT4 AS
DECLARE
p_user ALIAS FOR $1;
BEGIN
INSERT INTO user (id, pwd)
VALUES (p_user.id, p_user.pwd);
-- etc, etc, etc
END

then, from the client I might do something like:

SELECT add_user('{john, john123}');

with something like this I can get around Postgres'
limit of 32 parameters without having to compile a
custom version of the DB. One of the entities we're
working has many more than 32 parts which I'd rather
not have to split.

Regards,
Iker

Tom Lane wrote:

Show quoted text

Iker Arizmendi <iker@research.att.com> writes:

How are function parameters of rowtype specified when
calling them from a client such as libpq?

Something like
select myfunc(t.*) from tab t where ...

regards, tom lane

#4Iker Arizmendi
iker@research.att.com
In reply to: Iker Arizmendi (#3)
client IP address

Does Postgres provide a builtin mechanism to
obtain the IP address of the client that is executing
the current query?

Thanks,
Iker