bigquery-emulator icon indicating copy to clipboard operation
bigquery-emulator copied to clipboard

Error with Variable Declaration in BigQuery query -> Statement NOT supported

Open windsurfing33 opened this issue 6 months ago • 0 comments

What happened?

I am encountering an issue when attempting to run a BigQuery query that involves declaring a temporary variable and performing explicit type conversions. The query works fine in the standard BigQuery environment but fails when run in the BigQuery emulator. Below is the script that is causing the problem:

Query

` DECLARE target_date DATE;

SET target_date = ( SELECT DATE(date) -- Convertir la colonne date en type DATE FROM {bigquery_service.project_id}.{bigquery_service.dataset_id}.{bigquery_service.table_id} WHERE conversation.botman_session = @botman_session_value AND date IS NOT NULL LIMIT 1 );

SELECT * FROM {bigquery_service.project_id}.{bigquery_service.dataset_id}.{bigquery_service.table_id} WHERE DATE(date) = target_date AND conversation.botman_session = @botman_session_value; `

Error message :

{ "message": "Catching global error: 500 failed to analyze: INVALID_ARGUMENT: Statement not supported: VariableDeclaration [at 3:9]; message: failed to analyze: INVALID_ARGUMENT: Statement not supported: VariableDeclaration [at 3:9], reason: jobInternalError }

What did you expect to happen?

The query should run successfully, declaring the variable target_date and using it in the main query for comparison.

How can we reproduce it (as minimally and precisely as possible)?

The query fails with the error: INVALID_ARGUMENT: Statement not supported: VariableDeclaration.

Anything else we need to know?

No response

windsurfing33 avatar Jul 27 '24 16:07 windsurfing33