Re: Inability to cast regclass is too restrictive

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Inability to cast regclass is too restrictive
Дата
Msg-id 23914.1097296505@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Inability to cast regclass is too restrictive  (Oliver Elphick <olly@lfix.co.uk>)
Ответы Re: Inability to cast regclass is too restrictive  (Oliver Elphick <olly@lfix.co.uk>)
Список pgsql-hackers
Oliver Elphick <olly@lfix.co.uk> writes:
> 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.

Hmm?  plpgsql is about as permissive as you can get on this point.
Just assign the result to a variable of the desired type, and it will
do it if the textual representations are at all compatible.  Example:

regression=# create function foo(oid) returns text as '
regression'# declare z text;
regression'# begin
regression'#   z := $1::regclass;
regression'#   return z;
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select 'pg_proc'::regclass::oid;oid  
------1255
(1 row)

regression=# select foo(1255);                 foo   
---------pg_proc
(1 row)

> This seems overly restrictive.  Would there be a problem in allowing
> regclass() to be cast to text?

I'm on record that we should allow (explicit) casting to and from text
for all types, using the types' I/O functions to implement it.  But
plpgsql already provides essentially that mechanism in its assignment
operations.  You just hafta do the explicit assignment...
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [BUGS] BUG #1270: stack overflow in thread in fe_getauthname
Следующее
От: Tom Lane
Дата:
Сообщение: Re: more dirmod CYGWIN (was: APR 1.0 released)