Я использую Golang, PostgreSQL и go -pg (https://github.com/go-pg/pg).
Мне нужен этот запрос:
WITH cte AS (
SELECT
"player"."id",
"player"."created_at",
"player"."note"
FROM
"players" AS "player"
ORDER BY
"amount" DESC,
"id"
LIMIT 5
) ( SELECT * FROM cte ) UNION ALL
(
SELECT
"id",
"created_at",
CONCAT_WS ( '|', LAST_VALUE ( "created_at" ) OVER ( ), LAST_VALUE ( "id" ) OVER ( ) ) AS note
FROM
cte -- THIS IS CORRECT
LIMIT 1
)
и вместо этого go-pg
продолжает давать мне это:
WITH "cte" AS (
SELECT
"player"."id",
"player"."created_at",
"player"."note"
FROM
"players" AS "player"
ORDER BY
"amount" DESC,
"id"
LIMIT 5
) ( SELECT * FROM "cte" ) UNION ALL
(
SELECT
"id",
"created_at",
CONCAT_WS ( '|', LAST_VALUE ( "created_at" ) OVER ( ), LAST_VALUE ( "id" ) OVER ( ) ) AS note
FROM
"players" AS "player" -- THIS IS THE PROBLEM, I need "cte" here
LIMIT 1
)
Я использую этот код:
var players []*models.Player
queryAll := r.db.Model(&players).Limit(5)
queryNotes := r.db.Model((*models.Player)(nil)).ExcludeColumn("note").Limit(1)
queryNotes.ColumnExpr("CONCAT_WS ( '|', " + lastValues + " ) AS note")
err := queryAll.WrapWith("cte").Table("cte").UnionAll(queryNotes).Select(&players)
Что я могу сделать, чтобы это исправить?