Comments (5)
Outside of a window context this transformation is incorrect for a different reason:
In [7]: sg.parse_one("select x from t order by 1 nulls last", read="duckdb").sql("mysql")
Out[7]: 'SELECT x FROM t ORDER BY CASE WHEN 1 IS NULL THEN 1 ELSE 0 END, 1'
The 1
in ORDER BY 1
in the original query refers to a column in ordinal position, whereas the transformed query contains CASE WHEN 1 IS NULL
. The 1
in that case is an integer expression and so the case statement will always test FALSE
.
from sqlglot.
@tobymao I see you closed this, but the issue seems to remain for RANGE
windows.
from sqlglot.
@cpcloud could you elaborate more on what the issue is? we don't do the transform anymore when i try it.
python -m sqlglot "select sum(x) over (order by 1 nulls last range between 1 preceding and current row)" --read=duckdb --write=mysql
'NULLS LAST' not supported with positional ordering
SELECT
SUM(`x`) OVER (ORDER BY 1 range BETWEEN 1 preceding AND CURRENT ROW)
from sqlglot.
You have to use a non-ordinal-position expression:
❯ python -m sqlglot "select sum(x) over (order by x nulls last range between 1 preceding and current row)" --read=duckdb --write=mysql
SELECT
SUM(`x`) OVER (ORDER BY CASE WHEN `x` IS NULL THEN 1 ELSE 0 END, `x` range BETWEEN 1 preceding AND CURRENT ROW)
from sqlglot.
from sqlglot.
Related Issues (20)
- Incorrect `DATE_SUB` output in BigQuery HOT 1
- Unsupported expression type ArrayContained
- Invalid expression / Unexpected token
- doris not support ->> character , but from postgres transform the ->> character does not change HOT 3
- Add support for `CREATE STREAMLIT` HOT 1
- Add better support for `plpython3u` user-defined functions in PostgreSQL HOT 1
- rows alias is key , execute error HOT 3
- Support for X-prefixed Hex Strings in Databricks HOT 2
- postgres has problems with interval dates with ago HOT 2
- rows as a keyword not be execute in mysql or doris , The others are range/else HOT 1
- doris has more keywords than mysql HOT 1
- postgres STRING_TO_ARRAY function for doris is SPLIT_BY_STRING HOT 3
- The three functions WEEKOFYEAR, DAYOFMONTH, and DAYOFWEEK were incorrectly converted in Hive.
- Snowflake Alter Table ... Alter Column ... DROP NOT NULL doesn't parse correctly
- Potential bug in optimize when including schemas in sql query HOT 2
- Potential bug in optimize when including schemas in sql query HOT 1
- Snowflake Alter Table ... Add Column ... WITH TAG (...) doesn't parse correctly
- The REGEXP_SPLIT_TO_TABLE function for postgres is not present in doris, but the transfer does not seem to know this HOT 1
- Regression when parsing complex types with databricks dialect
- Possible regression when parsing complex types with databricks dialect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlglot.