examples with execute

From: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: examples with execute
Date: 2002-05-24 14:11:20
Message-ID: 73309C2FDD95D11192E60008C7B1D5BB04C73ACB@snt452.corp.bcbsm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Howdy:

Running Postgres 7.1.3 on RedHat Linux.

Can someone give me an example of
using the EXECUTE command while
in a function? For example, I'd like to
create a table using EXECUTE, but I'm
not sure about it's use (or how to use
create in a function).

My goal is to do something like this:

[snip code]

drop function t_member_cnt(int);
create function t_member_cnt(int)
returns integer
as '
declare nCnt int4;

begin
select count (*) from test_table into nCnt;
if nCnt < 1500000 then
return nCnt;
else
execute drop test_table;
execute select * into test_table from standby_table
where user_id=''3924'';
end if;
return nCnt;
end; '
language 'plpgsql';

-- change to user and execute the function
--
\c database joeuser
select t_member_cnt(0);

-- do the permissions part
--
grant select on test_table to public
drop index test_i;
create index test_i;

[/snip code]

Perhaps I've missed it, but I haven't see much in the
way of 'real world examples' using execute.

Suggestions welcomed!

Thanks!

-X

Browse pgsql-general by date

  From Date Subject
Next Message Olonichev Sergei 2002-05-24 14:30:09 How to add big amounts of data into database?
Previous Message mathieu.chappuis@msg-software.com 2002-05-24 14:09:54 Strange Result with char concatenation in query.