0

I am puzzled by this error:

"invalidQuery", "message": "Field 'QLD' not found in table 'medicare.medicareTable'.", "locationType": "other", "location": "query" } ], "code": 400

because the field QLD is most definitely in that table.

I am trying to get a response from BigQuery using the following query in a php file:

$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);

I have played around with the query and found that if I replace $qld with a string, e.g.:

WHERE State = 'QLD'

Then it works. I am at a loss. What is going wrong here?

Here's the full error, in case it's needed:

Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "invalidQuery", "message": "Field 'QLD' not found in table 'medicare.medicareTable'.", "locationType": "other", "location": "query" } ], "code": 400, "message": "Field 'QLD' not found in table 'medicare.medicareTable'." } } ' in /base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Http/REST.php:118 Stack trace: #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 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Task/Runner.php(181): call_user_ in /base/data/home/apps/s~s3449107-assign2/1.396261573977805792/php/google-api-php-client/src/Google/Http/REST.php on line 118

helpmeplz
  • 151
  • 1
  • 3
  • 11
  • Possible duplicate of [When to use single quotes, double quotes, and backticks?](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks) – chris85 Oct 11 '16 at 12:53
  • You have a low rate. Important on SO, you have to mark accepted answers by using the tick on the left of the posted answer, below the voting. This will increase your rate. See how this works by visinting this link: http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work#5235 – Pentium10 Oct 11 '16 at 13:10

1 Answers1

2

Not

WHERE State = $qld

But

WHERE State = '$qld'

Text is text ;)

nospor
  • 4,190
  • 1
  • 16
  • 25