Re: How to get Relation name from Oid ??

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Tom Hebbron" <news_user(at)hebbron(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: How to get Relation name from Oid ??
Date: 2004-03-10 00:33:18
Message-ID: 534.1078878798@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Tom Hebbron" <news_user(at)hebbron(dot)com> writes:
> If you need to use the path returned from the regclass cast as text, you
> will need to create a cast from regclass to text - this can be achieved
> using the following functions - making use of the cstring type that the
> return/input functions for these types have in common. I'd not sure how safe
> an approach this is - and would appreciate any comments.

This works, and is safe in versions where cstring is a full-fledged type
(I forget whether that was in 7.3 or 7.4).

But it might be notationally cleaner to use plpgsql. plpgsql's idea of
type coercion is to do exactly this output-to-string-and-input-again
trick, so the functionality would be the same, but you'd only need to
write

CREATE OR REPLACE FUNCTION utilities.text(regclass) RETURNS text STRICT
STABLE AS 'begin; return $1; end' LANGUAGE plpgsql;

I am not sure about speed considerations. Pre-7.4 the SQL function
method would certainly be slower, but as of 7.4 you can probably inline
the SQL function and it might come out ahead.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2004-03-10 00:49:34 Re: pgFoundry WAS: On pgweb project
Previous Message Bill Moran 2004-03-10 00:31:06 Re: Shouldn't B'1' = 1::bit be true?