Support for UNION

Open
#404 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
sqlite, swift
Domain
database

Research direction

Start by reading the documented “Executing Arbitrary SQL” approach and the query-building API used for JOINs. Determine how UNION inside a JOIN should be represented and how the resulting row can be passed to TableAObj; done means the feature or a documented workaround covers this query and its row type.

Written by the indexing model from the issue text.

Description

enhancement

I came across a use case where I need to write somewhat complex query using UNION inside the JOIN. The query looks something like below:

SELECT
    *
FROM
    table_a a
    JOIN table_b b ON b.a_id = a.id
    JOIN (
        SELECT id, val FROM table_c
        UNION
        SELECT id, val FROM table_d
    ) as e ON e.id = a.id

I don't believe UNION is supported yet. Can I ask a feature request for it?

If it's not possible (or while UNION is not implemented yet or is being implemented), can you suggest me a work-around? I tried using "Executing Arbitrary SQL" way as documented, but I can't find out the type of row in the snippet below. Ideally I'd like to pass row to my model for object generation.

let stmt = try db.prepare("SELECT * FROM table_a a JOIN table_b b ON b.a_id = a.id")
for row in stmt {
    let tableAObj = TableAObj(row)
}
Dominant language
Swift
Stars
10.2k
Forks
1.6k
Avg merge
6d 2h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stephencelis/SQLite.swift

All issues in stephencelis/SQLite.swift

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.