简体   繁体   English

PostgreSQL 是否可以参数化查询中使用的表名?

[英]PostgreSQL is it possible to parameterize the table name used in a query?

In PostgreSQL, is it possible to parameterize the table name used in a query?在 PostgreSQL 中,是否可以参数化查询中使用的表名?

Think of parameters as a replacement for scalar values only.仅将参数视为标量值的替代品。 Use one parameter in the place where you could use one string literal or numeric literal.在可以使用一个字符串文字或数字文字的地方使用一个参数。

You cannot use parameters for other parts of an SQL query:您不能将参数用于 SQL 查询的其他部分:

  • Identifiers like table names, column names, etc.标识符,如表名、列名等。
  • SQL keywords SQL 关键字
  • Expressions表达式
  • Lists of values, such as in an IN (...) predicate.值列表,例如在IN (...)谓词中。 Each value in the list would need an individual parameter.列表中的每个值都需要一个单独的参数。

All those parts of the SQL query must be fixed by the time the query is parsed during prepare() . SQL 查询的所有这些部分必须在prepare()期间解析查询时修复。 If a client library supports "parameters" for identifiers, it's really doing string-interpolation into the SQL query before the query is parsed.如果客户端库支持标识符的“参数”,它实际上是在解析查询之前对 SQL 查询进行字符串插值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用包含的 SQL 子查询中的值作为其包含查询的表名 - Is it possible to use the value from enclosed SQL sub-query to be used as the the table name for its encompassing query 是否可以在PostgreSQL中创建一个带有变量名的表? - Is it possible to create a table with a variable name in PostgreSQL? PostgreSQL使用连接表进行分区 - 在查询计划中不使用分区约束 - PostgreSQL partitioning with joined table - partition constraint not used in query plan 是否可以在Access中的查询表中更改列的名称? - Is it possible to change the name of a column in a query table in Access? Entity Framework Core,执行原始 SQL 并参数化表名 - Entity Framework Core, execute raw SQL and parameterize table name 是否可以将列表项名称存储到可以在SQL查询中使用的变量中? - Is it possible to store a list item name into a variable that can be used in an SQL query? Postgresql 查询 GROUP BY 不可能 - Postgresql query GROUP BY not possible 如何从PHP或Postgresql中的当前查询获取表名 - How to get table name from current query in php or postgresql 如何使用PostgreSQL从表名中获取列属性查询? - How to get column attributes query from table name using PostgreSQL? 是否可以通过oracle中的select查询将表名传递给SQL查询 - Is it possible to pass a table name to a SQL query by select query in oracle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM