Does indentation matter in SQL?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-29 04:07:26

问题


I'm doing a microcourse on Kaggle on which two seemingly identical blocks (except the indentation) produce different results.

1.

answers_query = """
                SELECT a.id, a.body, a.owner_user_id
                FROM `bigquery-public-data.stackoverflow.posts_questions` AS q 
                INNER JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a
                ON q.id = a.parent_id
                WHERE q.tags LIKE '%bigquery%'
                """
# Set up the query
safe_config = bigquery.QueryJobConfig(maximum_bytes_billed=10**10)
answers_query_job = client.query(answers_query, job_config = safe_config) # Your code goes here

# API request - run the query, and return a pandas DataFrame
answers_results = answers_query_job.to_dataframe() # Your code goes here

# Preview results
print(answers_results.head())

# Check your answer
q_4.check()

Running this code, I get the following error:

400 GET https://dp.kaggle.net/bigquery/v2/projects/kaggle-161607/queries/fdc91d96-2162-4e88-895e-7b0e2ffc377e?maxResults=0&location=US: Query exceeded limit for bytes billed: 10000000000. 25131220992 or higher required.

However when I just replace my answers_query as follows there is no error:

answers_query = """
                SELECT a.id, a.body, a.owner_user_id
                FROM `bigquery-public-data.stackoverflow.posts_questions` AS q 
                INNER JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a
                    ON q.id = a.parent_id
                WHERE q.tags LIKE '%bigquery%'
                """

It seems like different indentation is producing different results. I'm extremely new to SQL so I don't know if indentation should matter. From googling and other stack overflow answers it seems indentation is a matter of readability and it shouldn't change things.


回答1:


I had also similar kind of problem on Kaggle.com. Kaggle.com online editor interpret syntax in their own way.sometime kaggle interpreter intrpret wrongly. basically kaggle ide primarly targeted to support python. thats why some time indentation matters in kaggle online IDE




回答2:


Indentation definitely does not matter. As others have implied, the first query will likely be the slower as data is read from disk and cached. Subsequent queries on same data should be faster and will then be within the limit that caused the initial error.




回答3:


Indentation does not matter as the system reads it regardless of the space.



来源:https://stackoverflow.com/questions/62484555/does-indentation-matter-in-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!