Missing whitespace between literal and alias at in bigquery sql

Viewed 8000

I have this SQL query:

SELECT job_id 
FROM user_job fb 
WHERE extract(date from timestamp) BETWEEN extract(Date from 2021-03-17)

and I get this error:

google.api_core.exceptions.BadRequest: 400 Syntax error: Missing whitespace between literal and alias at [1:137]

3 Answers

BigQuery automatically recognizes well-formatted dates depending on the context. In your case your query can be simplified in

SELECT
    job_id
FROM
    user_job
WHERE
    `timestamp` BETWEEN "2021-03-17" AND "2021-03-31"

The most important here are the quotes: your dates must be inside single or double quotes, and here since "timestamp" is a BigQuery function, you need to specify its a column name by using the back quotes `` (or use an alias as you did but not necessary, actually the back quotes are not necessary either -BQ understands- but it's cleaner)

You need to put datetimes into DATETIME 'xxxxx':

SELECT job_id 
FROM user_job fb 
WHERE extract(date from fb.timestamp) BETWEEN extract(Date from '2021-03-17T14:26:56') and extract(Date from '2021-03-31T14:26:56')

I have the same error , only code 400

It turns out the database had a name starts with a digit So in this case the name of the database need to quoted:

Example: If the database name is "1Test" Instead of

SELECT * FROM 1Test.table1

It should be :

SELECT * FROM `1Test.table1`
Related