Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Aliased Query (CTE) with Union #818

Open
maen-allaga opened this issue Oct 4, 2024 · 2 comments
Open

Using Aliased Query (CTE) with Union #818

maen-allaga opened this issue Oct 4, 2024 · 2 comments

Comments

@maen-allaga
Copy link

I'm trying to build a query that is equivalent to the one here:

WITH some_alias AS (
  SELECT *
  FROM table_1
  WHERE ....
)
SELECT col1, col2
FROM some_alias
WHERE condition1 AND condition2
UNION ALL
SELECT col3, col4
FROM some_alias
WHERE condition3 OR condition4

In a previous issue ( #359 ) there a mention to add the ctes to the first query, but here I want the CTE to be available to both parts of the union.
Is that possible? Is there a way to extend the _SetOperation to add a with_ part?

@tiagoskaneta
Copy link

@maen-allaga did you eventually figure this out? I have the same issue.

@maen-allaga
Copy link
Author

@maen-allaga did you eventually figure this out? I have the same issue.

I created a wrapper around _SetOperations to handle the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants