sql-kit icon indicating copy to clipboard operation
sql-kit copied to clipboard

Insert values except / merge

Open CrownedPhoenix opened this issue 8 months ago • 3 comments

I'd like do be able to structure a query like:

INSERT INTO <table>
VALUES <values>  EXCEPT
SELECT <cols> FROM <table>

There might be a way to do this that I'm not sure of but some of the directions I went down were:

db.insert(into: <table>).values(...).except(...) // Not an API

db.insert(into: <table>).select(SQLSubQuery.select({
  $0.values(...).union(...) // Not an API
}))

db.insert(into: <table>).select(SQLSubQuery.except({
    $0.values(...)
  }).except(...) // Not an API
)

Context: My ultimate objective is to perform a merge but I know that is not general SQL so I'm trying to get as close an approximation I can with a single query.

CrownedPhoenix avatar Jun 13 '24 18:06 CrownedPhoenix