fix: correct tag alias references in SearchTagsValues query

- Change all tag.value references to tag in SearchTagsValues query
- Fix PostgreSQL error: "column tag.value does not exist"
- CROSS JOIN LATERAL unnest() creates alias 'tag', not 'tag.value'
- Updates SELECT, WHERE, GROUP BY, and ORDER BY clauses
- Regenerate Go code with sqlc generate

When using CROSS JOIN LATERAL unnest(mi.tags_search) AS tag,
PostgreSQL creates 'tag' as the column alias, not 'tag.value'.
This fix aligns all references to use just 'tag', matching the
actual column name created by the LATERAL join.

Resolves tags autocomplete SQLSTATE 42703 error.

Relates to TestTagsFilter tags autocomplete test
This commit is contained in:
2026-03-25 20:57:14 -04:00
parent c4ebbd990c
commit 0f70f74f12
2 changed files with 12 additions and 12 deletions
+6 -6
View File
@@ -7561,19 +7561,19 @@ func (q *Queries) SearchSeriesValues(ctx context.Context, arg SearchSeriesValues
const SearchTagsValues = `-- name: SearchTagsValues :many
SELECT
tag.value::TEXT as value,
tag::TEXT as value,
COUNT(*) as count,
word_similarity($1, tag.value)::float8 as score
word_similarity($1, tag)::float8 as score
FROM media_items mi
JOIN libraries l ON mi.library_id = l.id
LEFT JOIN library_visibility lv ON l.id = lv.library_id AND lv.user_id = $2
CROSS JOIN LATERAL unnest(mi.tags_search) AS tag
WHERE COALESCE(lv.is_visible, true) = true
AND ($3::uuid IS NULL OR mi.library_id = $3::uuid)
AND tag.value IS NOT NULL
AND word_similarity($1, tag.value) > 0.3
GROUP BY tag.value, word_similarity($1, tag.value)::float8
ORDER BY word_similarity($1, tag.value)::float8 DESC, COUNT DESC
AND tag IS NOT NULL
AND word_similarity($1, tag) > 0.3
GROUP BY tag, word_similarity($1, tag)::float8
ORDER BY word_similarity($1, tag)::float8 DESC, COUNT DESC
LIMIT $5 OFFSET $4
`
+6 -6
View File
@@ -565,19 +565,19 @@ LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset');
-- name: SearchTagsValues :many
SELECT
tag.value::TEXT as value,
tag::TEXT as value,
COUNT(*) as count,
word_similarity(sqlc.narg('search_query'), tag.value)::float8 as score
word_similarity(sqlc.narg('search_query'), tag)::float8 as score
FROM media_items mi
JOIN libraries l ON mi.library_id = l.id
LEFT JOIN library_visibility lv ON l.id = lv.library_id AND lv.user_id = sqlc.narg('user_id')
CROSS JOIN LATERAL unnest(mi.tags_search) AS tag
WHERE COALESCE(lv.is_visible, true) = true
AND (sqlc.narg('library_id')::uuid IS NULL OR mi.library_id = sqlc.narg('library_id')::uuid)
AND tag.value IS NOT NULL
AND word_similarity(sqlc.narg('search_query'), tag.value) > 0.3
GROUP BY tag.value, word_similarity(sqlc.narg('search_query'), tag.value)::float8
ORDER BY word_similarity(sqlc.narg('search_query'), tag.value)::float8 DESC, COUNT DESC
AND tag IS NOT NULL
AND word_similarity(sqlc.narg('search_query'), tag) > 0.3
GROUP BY tag, word_similarity(sqlc.narg('search_query'), tag)::float8
ORDER BY word_similarity(sqlc.narg('search_query'), tag)::float8 DESC, COUNT DESC
LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset');
-- name: SearchSeriesValues :many