SQL BigQuery:在查询

时间:2016-10-11 12:48:36

标签: php sql google-bigquery

我对这个错误感到困惑:

  

" invalidQuery"," message":" Field' QLD'表格' medicare.medicareTable'。"," locationType":"其他"," location":&#34 ;查询" }],"代码":400

因为字段QLD绝对在该表中。

我试图在php文件中使用以下查询从BigQuery获得响应:

$qld = 'QLD';

$request = new Google_Service_Bigquery_QueryRequest();

$request->setQuery("SELECT Gender, SUM(Cost) AS Cost
FROM [medicare.medicareTable]
WHERE State = $qld
GROUP BY Gender");

$response = $bigquery->jobs->query($projectId, $request);

我玩过这个查询,发现如果我用字符串替换$ qld,例如:

WHERE State = 'QLD'

然后它有效。 我很茫然。这里出了什么问题?

如果需要,请填写完整错误:

  

致命错误:未捕获的异常' Google_Service_Exception'消息' {"错误":{"错误":[{"域":"全球","原因":" invalidQuery"," message":" Field' QLD'表格' medicare.medicareTable'。"," locationType":"其他"," location":&#34 ;查询" },"代码":400,"消息":"字段' QLD'表格中没有找到医疗保险。医疗保险。'。" }'在/base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Http/REST.php:118堆栈跟踪:#0 / base / data / home /apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Http/REST.php(94):Google_Http_REST :: decodeHttpResponse(Object(GuzzleHttp \ Psr7 \ Response),Object( GuzzleHttp \ Psr7 \ Request),' Google_Service _...')#1 [内部函数]:Google_Http_REST :: doExecute(对象(GuzzleHttp \ Client),Object(GuzzleHttp \ Psr7 \ Request),&# 39; Google_Service _...')#2 /base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Task/Runner.php( 181):第118行的/base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Http/REST.php中的call_user_

1 个答案:

答案 0 :(得分:2)

WHERE State = $qld

但是

WHERE State = '$qld'

文字是文字;)