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

Support UNION queries #790

Closed
wants to merge 5 commits into from
Closed

Support UNION queries #790

wants to merge 5 commits into from

Conversation

aitva
Copy link
Contributor

@aitva aitva commented Nov 17, 2020

This pull request adds support for queries with an UNION keyword. I found a way to support them with a small update to internal/compiler.

I noticed that an UNION changes how ast.SelectStmt is parsed:

  • the TargetList field is empty
  • the Larg and Rarg fields contain the two part of the union

By changing outputColumns to look at the Larg field when TargetList is empty, the columns are returned and the code generation succeed.

I have added test cases for a SELECT with an UNION and a WITH RECURSIVE query.

It should fix #568, #723 and #778.

This commit adds support for `UNION` in `internal/compiler`. It also adds
test cases for `UNION` in a `SELECT` and in a `WITH RECURSIVE` query.

It fixes sqlc-dev#568, sqlc-dev#723 and sqlc-dev#778.
@aitva
Copy link
Contributor Author

aitva commented Dec 1, 2020

I have noticed that there are TODOs in engine/dolphin to add UNION support for MySQL and I think I can make it work. @kyleconroy, do you know if someone is working on it?

@kyleconroy
Copy link
Collaborator

kyleconroy commented Dec 1, 2020 via email

@aitva
Copy link
Contributor Author

aitva commented Dec 1, 2020

No problem, I am not in a rush. You can review this PR when you have time and I will send you another one when I have something working for MySQL.

This commit adds enum values for SetOperation. The values are extracted from
the parser sources in pg_query_go:

typedef enum SetOperation
{
    SETOP_NONE = 0,
    SETOP_UNION,
    SETOP_INTERSECT,
    SETOP_EXCEPT
} SetOperation;
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

Successfully merging this pull request may close these issues.

Union support for Postgres
2 participants