Hi Pavel, thanks! Yeah, thats what I though. I have to have a custom type or a very ugly looking solution for passing the params then.
To Postgre dev. team: If anyone who involved in Postgre development reading this, just a feature suggestion: allow array that can accept combination of any data types to be passed to a function, for example:
// declare
create function TEST ( anytypearray[] ) ...
// calling
perform TEST (array[bool, int, etc.] ) ....
This would make such a nice adition to the development for postgre. Although this may be complecated to achieve.
Thanks!
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Greg <grigorey@yahoo.co.uk>
Cc: pgsql-hackers@postgresql.org
Sent: Mon, 25 October, 2010 17:46:47
Subject: Re: [HACKERS] Composite Types and Function Parameters
Hello
I am thinking, so it isn't possible. There are a general datatype anyelement, but it cannot accept a second general type record.
CREATE TYPE p AS (a text, b int, c bool);
CREATE OR REPLACE FUNCTION fp(p)
RETURNS int AS $$
BEGIN RAISE NOTICE 'a = %', $1.a; RETURN $1.b;
END;
$$ LANGUAGE plpgsql;
postgres=# select fp(row('hello',10, false));
NOTICE: a = hello
fp
────
10
(1 row)
Regards
Pavel Stehule
Time: 0.814 ms
postgres=# select fp(row('hello',10, false));
2010/10/25 Greg
<grigorey@yahoo.co.uk>Hi guys, got across an interesting problem of passing params to a function in postgre: is it possible to pass a composite parameter to a function without declaring a type first?
For example:
// declare a function create function TEST ( object??? ) .... object???.paramName // using parameter ....
// calling perform TEST( ROW(string, int, bool, etc...) )
Or do I have to do the type declaration for that parameter?
Thanks!
|