table name in pl/pgsql

From: "ON(dot)KG" <skyer(at)on(dot)kg>
To: pgsql-general(at)postgresql(dot)org
Subject: table name in pl/pgsql
Date: 2004-11-25 16:42:21
Message-ID: 15933163937.20041125194221@on.kg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Smith 2004-11-25 16:49:06 Using IN with subselect
Previous Message Tom Lane 2004-11-25 16:32:18 Re: VACUUM ANALYZE question - PostgreSQL performance tests