kee
kee

Reputation: 11619

BigQuery: Syntax error: Unexpected keyword LEFT

I got this error of "Syntax error: Unexpected keyword LEFT" from the following SQL (standard SQL) in BigQuery:

select left(cast(ts as string), 16) from temp.loc limit 1;

"ts" is a timestamp field and I wanted to get upto minutes of timestamp. Any idea?

Upvotes: 2

Views: 9412

Answers (3)

joaopcoelho
joaopcoelho

Reputation: 61

For those looking for how to get the left-most characters in a string: Use LPAD instead of LEFT.

Example:

SELECT 
  LPAD('Hello', 3)

returns 'Hel'

Upvotes: 0

elithrar
elithrar

Reputation: 24250

If you want to extract the minutes from a timestamp field, use EXTRACT - https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#extract_1

EXTRACT(minutes from ts) as minutes

Upvotes: 0

Bobbylank
Bobbylank

Reputation: 1946

Left isn't a function in Standard SQL. Try using substr instead

SUBSTR

Upvotes: 4

Related Questions