Re: Getting the oid of an anyelement

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Scott Bailey <artacus(at)comcast(dot)net>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting the oid of an anyelement
Date: 2009-09-10 18:47:09
Message-ID: 162867790909101147g478b7b93p8a1a599129096656@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

please, try to look on function pg_typeof

postgres=# CREATE OR REPLACE FUNCTION x(anyelement)
RETURNS oid AS $$
SELECT pg_typeof($1)::oid; $$ LANGUAGE sql;
CREATE FUNCTION
postgres=# select x(10);
x
----
23
(1 row)

postgres=# select x(current_date);
x
------
1082
(1 row)

postgres=#

regards
Pavel Stehule

2009/9/10 Scott Bailey <artacus(at)comcast(dot)net>:
> If I've got a function (sql or plpgsql) that takes anyelement as a param,
> how do I determine the type name or oid that was actually passed in? I
> figure there is probably a function for this but darn if I can find it.
>
> Specifically, I'm trying to make a function like Oracle's dump that will
> take anything as input and return the internal representation of it. So I
> want to determine what type was passed in and call the appropriate send
> function.
>
>  SELECT dump(current_date);
>
>  dump
>  ------------------------------------------
>  Type=date OID=1082 Len=4 Data=(0,0,13,212)
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2009-09-10 18:52:07 Re: Unable to drop a table due to seemingly non-existent dependencies
Previous Message Peter Headland 2009-09-10 18:31:12 Re: COPY command character set