From cae3315e463b362b05ac0f369cdbcab7af97052d Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Mon, 24 Apr 2023 12:53:27 +0300 Subject: [PATCH] [#2349] fixed view query SELECT DISTINCT parsing --- CHANGELOG.md | 5 +++++ daos/view.go | 4 +++- daos/view_test.go | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4199bd..10a715a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## (WIP) v0.15.2 + +- Fixed view query `SELECT DISTINCT` identifiers parsing ([#2349](https://github.com/pocketbase/pocketbase/discussions/2349#discussioncomment-5706019)). + + ## v0.15.1 - Trigger the related `Record` model realtime subscription events on [custom model struct](https://pocketbase.io/docs/custom-models/) save ([#2325](https://github.com/pocketbase/pocketbase/discussions/2325)). diff --git a/daos/view.go b/daos/view.go index 0a409e27..22443225 100644 --- a/daos/view.go +++ b/daos/view.go @@ -462,6 +462,8 @@ func (p *identifiersParser) parse(selectQuery string) error { skip = false partType = "select" activeBuilder = &selectParts + case "distinct": + continue // ignore as it is not important for the identifiers parsing case "from": skip = false partType = "from" @@ -477,7 +479,7 @@ func (p *identifiersParser) parse(selectQuery string) error { partType = "join" activeBuilder = &joinParts case "_discard_": - // do nothing... + // skip following tokens skip = true default: isJoin := partType == "join" diff --git a/daos/view_test.go b/daos/view_test.go index d6db879a..c2b6c323 100644 --- a/daos/view_test.go +++ b/daos/view_test.go @@ -409,6 +409,20 @@ func TestCreateViewSchema(t *testing.T) { "custom": schema.FieldTypeJson, }, }, + { + "query with distinct and reordered id column", + `select distinct + id as id2, + id, + 123 as custom + from demo1 + `, + false, + map[string]string{ + "id2": schema.FieldTypeRelation, + "custom": schema.FieldTypeJson, + }, + }, } for _, s := range scenarios {