Refer to column/table names using strings?
is it possible to refer to a column/table name by using a string? Something like SELECT * FROM 'my_table'::table_name_t
?
The reason I'm asking: I have a table geometry_columns with some geometry tables. And I would like to know which objects are within a certain radiu开发者_C百科s.
Thanks, Philip
You will need a (stored) function to achieve this. The function takes the table name as an argument, creates the SQL dynamically and then returns the result of the SELECT based on that query.
here are some examples (not exactly what you need, but they should get you headed in the right direction):
http://forums.devshed.com/postgresql-help-21/plpgsql-variable-representing-table-name-137201.html
Dynamic column in SELECT statement postgres
I don't think you can do that directly. I think you would have to build the select statement from another statement or piece of code, then execute the resulting statement.
精彩评论