使用字符串引用列/表名称?
是否可以使用字符串引用列/表名称?像 SELECT * FROM 'my_table'::table_name_t
这样的东西?
我问的原因是:我有一个包含一些几何表的几何列表。我想知道哪些物体在某个半径内。
谢谢,菲利普
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 radius.
Thanks, Philip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要一个(存储的)函数来实现此目的。该函数将表名作为参数,动态创建 SQL,然后返回基于该查询的 SELECT 结果。
这里有一些示例(不完全是您需要的,但它们应该让您朝着正确的方向前进):
http://forums.devshed.com/postgresql-help-21/plpgsql-variable-representing-table-name-137201.html
SELECT 语句 postgres 中的动态列
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
我认为你不能直接这样做。我认为您必须从另一个语句或一段代码构建 select 语句,然后执行结果语句。
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.