Re: Composite Types and Function Parameters - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: Composite Types and Function Parameters
Date
Msg-id AANLkTi=NOJzWxMMiFA+tBLLZa44Q1Do1Qy5Cx=g1E_ra@mail.gmail.com
Whole thread
In response to Composite Types and Function Parameters  (Greg <grigorey@yahoo.co.uk>)
Responses Re: Composite Types and Function Parameters
List pgsql-hackers
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!


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: add label to enum syntax
Next
From: Jeff Davis
Date:
Subject: Re: Range Types, discrete and/or continuous