Reputation: 634
I have the function:
test(IN _partition)
Inside my function I would like to append the '_partition' to the beginning of my table name.
FROM table_ + '_partition'
The end result:
select * from test(12345);
This function will query the table: table_12345
Upvotes: 0
Views: 34
Reputation: 324475
You need PL/PgSQL dynamic SQL with EXECUTE
and the format
function, e.g.
RETURN QUERY EXECUTE format('SELECT * FROM %I', _partition);
However, this is a mark of a design that will probably be painful to work with.
Have you looked at PostgreSQL's table inheritance features?
Upvotes: 1