Git Product home page Git Product logo

Comments (5)

cpcloud avatar cpcloud commented on May 24, 2024

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.

cpcloud avatar cpcloud commented on May 24, 2024

@tobymao I see you closed this, but the issue seems to remain for RANGE windows.

from sqlglot.

tobymao avatar tobymao commented on May 24, 2024

@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.

cpcloud avatar cpcloud commented on May 24, 2024

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.

tobymao avatar tobymao commented on May 24, 2024

3f7748b

from sqlglot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.