|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have problems to install the following function
CREATE FUNCTION countrow(text ) /* name of table */ RETURNS bigint AS 'select count(*) from $1;' LANGUAGE 'sql'; I have a pile of dynamic generated tables and don't want to use triggers. It's easer to change one function instead of hundred table triggers. I know it's not common to use the function parameter for table name but maybe somebody has an idea and can help to make it work. Thanx miha |
|
#2
|
|||
|
|||
|
here is a thread about using a param for a table name in a plpgsql function. Do you need it to be SQL? you can probably do the same there, I've never tried. you can call plpgsql functions the same way as sql functions, it depends on what you need to return.
|
|
#3
|
|||
|
|||
|
This hint...
Hey Thank you, this was my problem. now it looks a little mor complex, but it is working...
CREATE OR REPLACE FUNCTION countRow (text) RETURNS int8 AS ' DECLARE table_name ALIAS FOR $1; table_row INTEGER; input_refc refcursor; BEGIN table_row := 0; RAISE NOTICE ''table name = %'', table_name; OPEN input_refc FOR EXECUTE ''SELECT count(*) FROM '' || quote_ident(table_name); RAISE NOTICE ''tablefetch = %'', input_refc; FETCH input_refc into table_row; CLOSE input_refc; RETURN table_row; END; ' LANGUAGE plpgsql; Thank you:-] |
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > CRATE FUNCTION for dynamic generated tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|