dbTalk Databases Forums  

How to describe functions.

comp.databases.postgresql comp.databases.postgresql


Discuss How to describe functions. in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mladen Gogala
 
Posts: n/a

Default How to describe functions. - 12-10-2009 , 11:13 AM






I would like to write a single query listing all of the function argument
types. I know that I can write a procedure but I would prefer a single
query. The problem is that in pg_proc, the column proargtypes is of the
type "oidvector", which is another name for an array oid[]. The types
are, of course in pg_type table. The problem here is the array handling.
what I would really like is something like this:

select p.proname,(for($i=0;$i<p.pronargs;$i++ { t.typename where
t.oid=p.proargtypes[$i] }
from pg_proc p, pg_type t;

Of course, I am aware that this is a bad syntax but this pseudocode is
the best way to describe what I want to achieve. The issue is the array
handling.



--
http://mgogala.byethost5.com

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to describe functions. - 12-11-2009 , 03:02 AM






Mladen Gogala wrote:
Quote:
I would like to write a single query listing all of the function argument
types. I know that I can write a procedure but I would prefer a single
query. The problem is that in pg_proc, the column proargtypes is of the
type "oidvector", which is another name for an array oid[]. The types
are, of course in pg_type table. The problem here is the array handling.
what I would really like is something like this:

select p.proname,(for($i=0;$i<p.pronargs;$i++ { t.typename where
t.oid=p.proargtypes[$i] }
from pg_proc p, pg_type t;

Of course, I am aware that this is a bad syntax but this pseudocode is
the best way to describe what I want to achieve. The issue is the array
handling.
You mean something like that?

SELECT
p.proname,
(SELECT array_agg(t.typname)
FROM unnest(p.proargtypes) AS o(oid) JOIN
pg_type AS t ON (o.oid=t.oid)) AS argtypes
FROM pg_proc AS p;

Yours,
Laurenz Albe

Reply With Quote
  #3  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: How to describe functions. - 12-11-2009 , 03:22 AM



Laurenz Albe, 11.12.2009 09:02:
Quote:
Mladen Gogala wrote:
I would like to write a single query listing all of the function argument
types. I know that I can write a procedure but I would prefer a single
query. The problem is that in pg_proc, the column proargtypes is of the
type "oidvector", which is another name for an array oid[]. The types
are, of course in pg_type table. The problem here is the array handling.
what I would really like is something like this:

You mean something like that?

SELECT
p.proname,
(SELECT array_agg(t.typname)
FROM unnest(p.proargtypes) AS o(oid) JOIN
pg_type AS t ON (o.oid=t.oid)) AS argtypes
FROM pg_proc AS p;

Yours,
Laurenz Albe

If you are on 8.4 you can use:

SELECT proname,
pg_catalog.pg_get_function_arguments(oid)
FROM pg_proc;

Thomas

Reply With Quote
  #4  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: How to describe functions. - 12-11-2009 , 05:22 PM



On Fri, 11 Dec 2009 09:02:58 +0100, Laurenz Albe wrote:

Quote:
Mladen Gogala wrote:
I would like to write a single query listing all of the function
argument types. I know that I can write a procedure but I would prefer
a single query. The problem is that in pg_proc, the column proargtypes
is of the type "oidvector", which is another name for an array oid[].
The types are, of course in pg_type table. The problem here is the
array handling. what I would really like is something like this:

select p.proname,(for($i=0;$i<p.pronargs;$i++ { t.typename where
t.oid=p.proargtypes[$i] }
from pg_proc p, pg_type t;

Of course, I am aware that this is a bad syntax but this pseudocode is
the best way to describe what I want to achieve. The issue is the array
handling.

You mean something like that?

SELECT
p.proname,
(SELECT array_agg(t.typname)
FROM unnest(p.proargtypes) AS o(oid) JOIN
pg_type AS t ON (o.oid=t.oid)) AS argtypes
FROM pg_proc AS p;

Yours,
Laurenz Albe
Eh, yes, I was missing the "unnest" part. Thanks.



--
http://mgogala.byethost5.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.