can't figure out how to use CTE and values #131
-
Hi, give please advise, how to implement query with 'with' and 'values' closures via bob?
|
Beta Was this translation helpful? Give feedback.
Answered by
stephenafamo
Nov 22, 2023
Replies: 1 comment 5 replies
-
The main reason why this is not possible is that Bob currently does not yet have a way to build Since we already have the syntax down for inserts, I could try and make this work 🤔 . In the meantime, here is a way you can do this, relying on vals := clause.Values{}
vals.AppendValues(psql.S("1"), psql.S("data 1"))
vals.AppendValues(psql.S("2"), psql.S("data 2"))
vals.AppendValues(psql.S("3"), psql.S("data 3"))
psql.Update(
um.With("c", "id", "data").As(bob.BaseQuery[clause.Values]{
Expression: vals,
Dialect: dialect.Dialect,
}),
um.TableAs("test", "t"),
um.Set("data").To("c.data"),
um.From("c"),
um.Where(psql.Quote("c", "id").EQ(psql.Quote("t", "id"))),
) NOTE: I didn't actually run this code, but I bet it should work. Try it out and let me know. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
stephenafamo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The main reason why this is not possible is that Bob currently does not yet have a way to build
VALUES
queries. OnlySELECT
,UPDATE
,INSERT
andDELETE
.Since we already have the syntax down for inserts, I could try and make this work 🤔 .
In the meantime, here is a way you can do this, relying on
clause.Values