From: | Sameer Thakur <samthakur74(at)gmail(dot)com> |
---|---|
To: | 1378170386(dot)3581(dot)15(dot)camel(at)centos-dev(dot)machinemanagement(dot)com |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Stored Procedure table/column args |
Date: | 2013-09-08 11:42:04 |
Message-ID: | CABzZFEsaFPWwbNr=VZKPZPkPFaydrCCqeFXqykcG0xsH3VVc2w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
Create a view as described @
create view my_tbldescription as
select
u.usename, t.typname AS tblname,
a.attname, a.atttypid, n.typname AS atttypname,
int4larger(a.attlen, a.atttypmod - 4) AS atttyplen,
a.attnotnull, a.attnum
from pg_user u, pg_type t, pg_attribute a, pg_type n
where u.usesysid = t.typowner
and t.typrelid = a.attrelid and t.typtype = 'c' and not (t.typname ~*
'pg_')
and n.typelem = a.atttypid
and substr(n.typname, 1, 1) = '_'
and a.attnum > 0 ;
And then create functions using that view.
create or replace function table_exists (tbl varchar) returns boolean AS
$$
DECLARE
x integer;
BEGIN
Execute 'select count(*) from my_tbldescription where
tblname=$1' into x using tbl;
if (x>0)
then
RETURN TRUE;
else
RETURN FALSE;
end if;
END;
$$ LANGUAGE plpgsql;
create or replace function column_exists (col varchar) returns boolean AS
$$
DECLARE
x integer;
BEGIN
Execute 'select count(*) from my_tbldescription where
attname=$1' into x using col;
if (x>0)
then
RETURN TRUE;
else
RETURN FALSE;
end if;
END;
Regards
Sameer
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas 'ads' Scherbaum | 2013-09-08 13:27:50 | Re: Call for design: PostgreSQL mugs |
Previous Message | Marc Mamin | 2013-09-08 10:24:32 | Re: Hash Support Function |