Lara G
Lara G

Reputation: 37

Syntax error: Expected "(" or "," or keyword SELECT but got end of script

I just followed the query from the course but I could not figure out why I get the error message.

Syntax error: Expected "(" or "," or keyword SELECT but got end of script at [13:6]

With 
longest_used_bike AS (
    SELECT 
        Bikeid,
        SUM(duration_minutes) AS trip_duration
    FROM 
        bigquery-public-data.austin_bikeshare.bikeshare_trips
    GROUP BY 
        Bikeid
    ORDER BY 
        Trip_duration DESC
    LIMIT 1
)

Why do I get this error?

Upvotes: 1

Views: 33175

Answers (8)

Maria Hoffens
Maria Hoffens

Reputation: 1

Your WITH statement has to be the same number of columns as your SELECT statement.

WITH colum1, colum2 
As
(
  SELECT colum1, colum2 
  etc etc
)

At the moment you only have one column with and two when selecting.

Upvotes: 0

Anyumba
Anyumba

Reputation: 171

I had the same issue. I learned that the CTE (the WITH clause) can't work as a standalone piece of code - it is a part of a larger statement. To complete your code, you must add a SELECT statement.

Here is what I think happens:

  1. the WITH clause only creates your temporary table
  2. you need another statement to manipulate or query the temp table, a SELECT usually works.
WITH longest_used_bike AS (
  SELECT
    bikeid,
    SUM(duration_minutes) AS trip_duration
  FROM `bigquery-public-data.austin_bikeshare.bikeshare_trips`
  GROUP BY bikeid
  ORDER BY trip_duration DESC
)
/* add your SELECT statement here */
SELECT *
FROM longest_used_bike;

/* or whatever else */

Upvotes: 7

Jay Prakash
Jay Prakash

Reputation: 1

You Must Add your Query Since You Just created a 'Temporary Table' which will long last for the next 60 minutes, and you didn't add your query after creating a temp table so that's why you're getting an error.

As you created a temporary table add your query just below the temp table whithout ";" for reference look at this


With
longest_used_bike AS (
    SELECT 
        Bikeid,
        SUM(duration_minutes) AS trip_duration
    FROM 
        bigquery-public-data.austin_bikeshare.bikeshare_trips
    GROUP BY 
        Bikeid
    ORDER BY 
        Trip_duration DESC
    LIMIT 1
)

-- Example --

SELECT *
FROM longest_used_bike;

Upvotes: 0

Lohzg
Lohzg

Reputation: 11

I ran into this issue during a course.

Creating a temporary table in BigQuery without a SELECT statement at the bottom will result in this error. By adding a SELECT statement at the end will resolve the issue.

Hence, just add a statement below your created temporary table: SELECT * FROM longest_used_bike

Upvotes: 1

Maria
Maria

Reputation: 1

The activity has a note after the creation of the temp table that says "If you run it now, it’ll return an error because you haven’t written any queries yet. Now, it’s time to write a query that identifies the start station that this bike came out of." You just need to keep reading the activity and you will understand why errors occur.

And advice is to take a look at the activity before starting it, so you will know what you will encounter as you work through the activity.

Upvotes: 0

hanzo_shimada
hanzo_shimada

Reputation: 1

I ran into the same issue during the course today. By adding a SELECT statement at the end will resolve this. In this situation, we just created a temporary table without providing any query to use it in that is why we are getting this error.

You can find more about the syntax here:https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax

Upvotes: 0

Marcus
Marcus

Reputation: 13

I also ran into this issue during the course.

From the course, written under the image of code. "If you run it now, it’ll return an error because you haven’t written any queries yet. Now, it’s time to write a query that identifies the start station that this bike came out of."

To fix the issue add another SELECT statement.

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269503

You get this error because a CTE (i.e. the WITH statement) is only part of a query. It needs to be followed by another statement, usually a SELECT.

Perhaps you intend:

With longest_used_bike AS (
      SELECT Bikeid, SUM(duration_minutes) AS trip_duration
      FROM `bigquery-public-data.austin_bikeshare.bikeshare_trips`
      GROUP BY Bikeid
      ORDER BY Trip_duration DESC
      LIMIT 1
     )
select *
from longest_used_bike;

I also assume that you are using BigQuery. The table name needs to be inclosed in backticks.

Upvotes: 3

Related Questions