Re: How to return argument data type from sql function

Поиск
Список
Период
Сортировка
От Andrus
Тема Re: How to return argument data type from sql function
Дата
Msg-id c1976464-86d4-1839-7531-f4eff3cbce64@hot.ee
обсуждение исходный текст
Ответ на Re: How to return argument data type from sql function  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: How to return argument data type from sql function  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general

Hi!
>Yeah, you could do that if you have the column information at hand.

Personally I'd also throw in "... and atttypid = 'bpchar'::regtype",
because that atttypmod calculation will give you garbage for types
other than bpchar and varchar.

I added this:

create or replace function public.ColWidth(p_namespace text, p_table text, p_field text)
    returns int as $f$
select atttypmod-4 from pg_namespace n, pg_class c, pg_attribute a
 where n.nspname = p_namespace and
    c.relnamespace = n.oid and
    c.relname = p_table and
    a.attrelid = c.oid and
    atttypid = 'bpchar'::regtype and
    a.attname = p_field;
$f$ LANGUAGE SQL ;

Tables with same name are in different schemas.

How to change this query so that it searches schemas in set search_path order and returns column width from it ? In this case p_namespace parameter can removed.

Or should it replaced with dynamic query like

execute 'select ' || p_field || ' from ' || p_table || ' limit 0'

and get column size from this query result somehow ?

Andrus.

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

Предыдущее
От: Anthony DeBarros
Дата:
Сообщение: Where to flag an issue with EDB's PG15 Windows installer?
Следующее
От: Andrus
Дата:
Сообщение: Re: How to return argument data type from sql function