From: | Andrus <kobruleht2(at)hot(dot)ee> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to return argument data type from sql function |
Date: | 2022-10-14 21:48:35 |
Message-ID: | c1976464-86d4-1839-7531-f4eff3cbce64@hot.ee |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Andrus | 2022-10-14 21:56:33 | Re: How to return argument data type from sql function |
Previous Message | Anthony DeBarros | 2022-10-14 21:45:22 | Where to flag an issue with EDB's PG15 Windows installer? |