下面是我通过 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
。当我在列名别名(带空格)周围使用块引号从我的 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'