How to determine column datatypes in a CTE with SELECT based on an initial schema? #5462
Closed
ragunandhant
started this conversation in
General
Replies: 1 comment 3 replies
-
Hey, I think you should look into sqlglot/tests/test_optimizer.py Line 880 in 5a476a5 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@tobymao
I'm working on a project where I have a predefined database schema (similar to the example below) and I need to parse SQL queries to understand the resulting datatypes of columns, especially when CTEs (Common Table Expressions) and SELECT statements are involved.
My Goal: Given an initial schema and a SQL query, I want to programmatically determine the datatype of each column in the final result set of that query. This is relatively straightforward for direct table selections, but it becomes more complex with transformations and expressions within SELECT or CTEs.
In the above sql example, the active_users CTE selects id (INT) and name (VARCHAR(100)). The final SELECT then reorders them. I'd like to be able to output something like:
{
"name": "VARCHAR(100)",
"id": "INT"
}
Beta Was this translation helpful? Give feedback.
All reactions