带有间隔列名称别名

时间:2016-02-11 15:35:42

标签: php postgresql

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

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函数可以运行它?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您是否尝试在别名周围使用包含转义的引号(如果查询使用单引号,则不需要)?喜欢

<?php
    $datePOST = new DateTime($_POST['today']);
    echo $datePOST->format('d/m/Y');
?>

$query = "Select field as \"run duration in seconds\" from table"
相关问题