Skip to content

Add APPLY operator support for mssql #5133

Description

@everilae

The APPLY operator in mssql is somewhat akin to a JOIN LATERAL in postgresql and allows referencing columns from the left side of the FROM clause on the right side of the operand.

The goal is that

from sqlalchemy import select, table, column
from sqlalchemy.dialects.mssql import apply

t1 = table('t1', column('c1'))
t2 = table('t2', column('c1'), column('c2'))
subq = select([t2.c.c2]).where(t2.c.c1 == t1.c.c1).subquery()
stmt = select([t1.c.c1, subq.c.c2]).select_from(apply(t1, subq))

would produce something close to

SELECT t1.c1, anon_1.c2 FROM
t1 CROSS APPLY (SELECT t2.c2 FROM
t2 WHERE t2.c1 = t1.c1) AS anon_1

It is maybe noteworthy that Oracle has also implemented { CROSS | OUTER } APPLY and so maybe this feature should live in the generic SQL namespaces, instead of the mssql dialect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SQL ServerMicrosoft SQL Server, e.g. mssqlcode review in progresscode has been provided that's in review as PR and/or gerritoraclepatch providedissue has the correct patch present in the comments. needs test + mergesqluse casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions