| From: | Ying Lu <ying_lu(at)cs(dot)concordia(dot)ca> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | About using plpgsql funciton variable as the table name |
| Date: | 2005-08-11 15:00:06 |
| Message-ID: | 42FB67F6.6000207@cs.concordia.ca |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Greetings,
I met a question about how to use *function variable *as the *table
name* to select count(*) into an integer variable for the table.
CREATE OR REPLACE FUNCTION update_code_map(VARCHAR, VARCHAR) RETURNS
VARCHAR AS $$
DECLARE
*tableName ALIAS FOR $1*;
*rec_num INTEGER*;
query_value VARCHAR;
BEGIN
-- way 1
query_value := 'SELECT *INTO rec_num* COUNT(*) FROM ' || tableName
|| ' ';
EXECUTE query_value;
-- way 2
-- SELECT INTO rec_num COUNT(*) FROM tableName;
RAISE NOTICE 'There are % records in % table. ', rec_num,
tableName;
RETURN 'Populate ' || tableName || ' successfully!';
END;
$$ LANGUAGE plpgsql;
select update_code_map('code_map.dw_adm_dsn_map', '066');
I tried way 1 & way 2 , but neither of them worked. Could someone give
some clues?
Thanks a lot!
Emi
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Csaba Nagy | 2005-08-11 15:46:35 | Re: World-wide Stop Order on PERL,Python,Java::->> Use |
| Previous Message | David Fetter | 2005-08-11 14:57:24 | Re: Exceptions in PL/Perl? |