【发布时间】:2017-01-14 15:03:01
【问题描述】:
我有一个程序将表名的后缀作为输入。然后,使用执行格式(),我传递这个参数来执行动态查询。问题是这个参数在整个过程中都是相同的——我不想像这样传递它 x 次:
execute format('SELECT table_%s.field1, table_%s.field2,table_%s.field3
FROM table_%s', inTableSuffix, inTableSuffix, inTableSuffix, inTableSuffix, ...)
我想要类似于以下的格式:
execute format('SELECT table_%s.field1, table_%s.field2,table_%s.field3
FROM table_%s', inTableSuffix)
我知道我可以使用表名的别名来解决这个问题,但是还有其他选择吗?
【问题讨论】:
-
那么你有答案了吗?
标签: sql database postgresql plpgsql dynamic-sql