带有间隔列名称别名的 php 查询字符串

标签 php postgresql

下面是我通过成功运行的 php 作为字符串发送的 sql 查询的一部分。我需要做的就是将列名(包含“_”)更改为空格。

SELECT DISTINCT(g.test_case_id), test_case_path AS test_case, build_name, g.total_files_covered, g.total_files_in_build, round(cast(g.total_files_covered as numeric)/cast(g.total_files_in_build as numeric),4)*100 as file_coverage, g.total_functions_covered , g.total_functions_in_build, round(cast(g.total_functions_covered as numeric)  / cast(g.total_functions_in_build as numeric) ,4)*100 as function_coverage,run_duration AS run_duration_in_seconds FROM ( .... )

例如,最后一列名称是 run_duration_in_seconds 将其更改为 run duration in seconds 。当我在列名别名(带空格)周围使用 block 引号从我的 php 函数执行查询时。我得到错误:

Warning: pg_query(): Query failed: ERROR:  syntax error at or near "`"
LINE 2: ...ric) ,4)*100 as function_coverage,run_duration AS `run durat...  

我应该如何将列名别名(使用空格而不是下划线)添加到查询中,以便它可以由 php pg_query 函数运行?

非常感谢任何帮助。

最佳答案

您是否尝试过在您的别名周围使用带转义符的引号(但如果查询在单引号中则不需要)?喜欢

$query = "Select field as \"run duration in seconds\" from table"

$query = 'Select field as "run duration in seconds" from table'

关于带有间隔列名称别名的 php 查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343566/

相关文章:

php - 如何选择一个字段是数组成员的数据?

PHP & cURL 代理 - 如何制作多用户 cookie jar?

postgresql - Postgres 字符串函数(包括 regexp_*)是否将制表符视为空格?

ruby-on-rails - rails 3.1 : Querying Postgres for records within a time range

postgresql - Postgres 中的游标

php - 列出 cakePHP 3.x 中的所有表

php - 带有 foreach 循环的样式表

php - 循环访问多个 id 错误

postgresql - PostgreSQL 的错误信息字段

postgresql - Postgres 和 PostGis ,无法创建扩展