Re: Inability to cast regclass is too restrictive

From: Joe Conway <mail(at)joeconway(dot)com>
To: olly(at)lfix(dot)co(dot)uk
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Inability to cast regclass is too restrictive
Date: 2004-10-09 03:13:45
Message-ID: 41675769.6020600@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2004-10-09 03:20:16 Re: Allow change of kerberos service name without recompilation
Previous Message Christopher Browne 2004-10-09 02:10:19 Re: First set of OSDL Shared Mem scalability results, some wierdness ...