Skip to content

SQL double-colon casting destroys AST topology #137

@adrian-datacamp

Description

@adrian-datacamp

This postgresql query

SELECT CAST(unanswered_count/question_count AS numeric) AS computed_pct, unanswered_pct
  FROM stackoverflow
 WHERE question_count != 0;

generates a clean AST in the AST viewer.

screen shot 2019-01-22 at 3 00 23 pm

However, the equivalent query (in postgresql, at least)

SELECT unanswered_count/question_count::numeric AS computed_pct, unanswered_pct
  FROM stackoverflow
 WHERE question_count != 0;

where the type casting is done with a double colon (::) wipes out the AST topology:

screen shot 2019-01-22 at 3 00 42 pm

A consequence of this is that the topologies of ASTs of queries containing double colons are also broken, subsequently breaking SCTs (for an example, go to Exercise 2.3 in this course).

For additional information, this is severely affecting SCTs for SQL for Exploratory Data Analysis, which purposefully uses this casting syntax throughout the course.

cc: @yashasroy

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions