Code Monkey home page Code Monkey logo

Comments (3)

reata avatar reata commented on August 17, 2024

This is yet another moment when I feel amazed that it's allowed to write SQL like this.

To summarize, c2, c3 and c4 can come from src_tbl1 and src_tbl2

select
    c1,
    (select c2 || c3 || c4 from src_tbl1) as c2
------------^^^
from
    src_tbl2
;

Again, tried a few open source SQL database:

dialect version src_tbl1 returns multiple rows src_tbl1 returns 1 row
mysql 8.2.0 ERROR 1242 (21000): Subquery returns more than 1 row yes
postgres 16.1 ERROR: more than one row returned by a subquery used as an expression yes
hive 3.1.3 CalciteSubquerySemanticException [Error 10249]: Unsupported SubQuery Expression Currently SubQuery expressions are only allowed as Where and Having Clause predicates (state=42000,code=10249) same error
sparksql 3.5.0 [UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY] Unsupported subquery expression: Correlated scalar subqueries must be aggregated to return at most one row. same error
trino 435 Given correlated subquery is not supported same error

When src_tbl1 returns multiple rows, this SQL won't be executable. Hive/Spark/Trino disallow this syntax at parsing phase. MySQL/Postgres postpone throwing exception until execution and would allow if the subquery returns 1 row at execution time.

Generally speaking, I think it's a very narrow use case. And it requires a lot of change to sqllineage (we might need to introduce the concept of lexical scope, like Python doing variable lookup from local -> enclosed -> global -> built-in). That's error-prune and not adding too much value.

from sqllineage.

maoxingda avatar maoxingda commented on August 17, 2024

Our SQL does not have this kind of syntax. I just found this syntax when looking at the underlying sqlfluff, so I brought it up. Can be processed or not.

from sqllineage.

reata avatar reata commented on August 17, 2024

OK. We'll keep it open and take it as low priority then.

from sqllineage.

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.