I think you would have to do it something like this, although whether the SELECT INTO works in an EXECUTE context I am not sure (note, completely untested code!)
CREATE FUNCTION get_count(text, text) RETURNS int2 AS ' DECLARE cnt int4; BEGIN EXECUTE ''SELECT INTO cnt COUNT(*) FROM table_'' || $1 || '' WHERE key = '' || $2; RETURN cnt; END;' LANGUAGE 'plpgsql'; > New question: > > i have tables like > table_20041124, > table_20041125, > etc... > > i'm trying to make function (for example): > ===================================== > CREATE FUNCTION get_count(text, text) > RETURNS int2 AS ' > DECLARE > cnt int4; > BEGIN > SELECT INTO cnt COUNT(*) > FROM table_$1 -- That doesn't work > WHERE key = $2; > > RETURN cnt; > END;' > LANGUAGE 'plpgsql'; > ===================================== > > call this function by: > > ===================================== > SELECT get_count("20041124", "something"); > ===================================== > > string in funstion - FROM table_$1 > > how could i get a final correct table name here? > > Thanx! > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]