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

incorrect SQL generated by compilers when using update/insert/delete as a CTE #640

Open
ianclegg opened this issue Nov 16, 2022 · 0 comments

Comments

@ianclegg
Copy link

It appears SqlKata is unable to generate 'data-modifying' common table expressions (CTE's). This can be observed when using the fluent api to build a Query using the With method and passing an Insert, Update or Delete query.
In this scenario SqlKata behaves as if the query passed into the With method did not have the AsInsert(), AsUpdate() or AsDelete() methods invoked on it and instead generates select statements.

For example:

var insert = new Query("table_one").AsInsert(new[] {"column_one"}, new object[] { 1 });
var query = new Query("table_two").Select("column")
    .With("insert_query", insert)

expected result:

WITH "insert_query" AS (
  INSERT INTO "table_one" ("column_one") VALUES  (1)
)
SELECT "column" FROM "table_two"

actual result:

WITH "insert_query" AS (
  SELECT * FROM "table_one"
)
SELECT "column" FROM "table_two"
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

1 participant