Using value list in ANY() expression #1575
-
I wanted to try this optimisation: https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/ As I understand it when I do,
that generates the following,
but I need Any ideas how I can achieve that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I managed to craft it manually like this which isn't too bad. Will leave it here in case there is a better way or serves someone // https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/
values := make([]string, 0, len(ids))
for i := 1; i <= len(values); i++ {
values = append(values, fmt.Sprintf("($%d::uuid)", i))
}
valuesList := fmt.Sprintf("VALUES %s", strings.Join(values, ","))
rows, err := c.db.Query(ctx, fmt.Sprintf(`
SELECT ... WHERE id = ANY(%s)
`, valuesList), ids...) |
Beta Was this translation helpful? Give feedback.
-
I don't think that technique is useful anymore. See the end of that post:
Regardless though, I don't know of any way to do that technique aside from creating a custom SQL string each time like you are doing. |
Beta Was this translation helpful? Give feedback.
I don't think that technique is useful anymore. See the end of that post:
Regardless though, I don't know of any way to do that technique aside from creating a custom SQL string each time like you are doing.