Re: Inability to cast regclass is too restrictive - Mailing list pgsql-hackers

From Joe Conway
Subject Re: Inability to cast regclass is too restrictive
Date
Msg-id 41675769.6020600@joeconway.com
Whole thread Raw
In response to Inability to cast regclass is too restrictive  (Oliver Elphick <olly@lfix.co.uk>)
List pgsql-hackers
Oliver Elphick wrote:
> I tried to use regclass() in a plpgsql function to derive a tablename
> from its oid so as to build a command string, but I am unable to use the
> value returned because it cannot be cast to anything.  Therefore I will
> have to use a complex query on the catalog to do the same work.
> 
> This seems overly restrictive.  Would there be a problem in allowing
> regclass() to be cast to text?
> 

I agree (I've been frustrated by this myself before), but for a 
workaround, see the following:

create or replace function any2text(anyelement) returns text as'
begin return $1;
end
' language plpgsql;

select any2text(1255::oid::regclass) || ' is the relname in text';            ?column?
-------------------------------- pg_proc is the relname in text
(1 row)

HTH,

Joe


pgsql-hackers by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: APR 1.0 released
Next
From: Bruce Momjian
Date:
Subject: Re: Allow change of kerberos service name without recompilation