Lucid - JOIN with inline table #4948
Answered
by
thedomeffm
thedomeffm
asked this question in
Help
-
Is it possible in Lucid to write this query without SELECT s.*
FROM products s
JOIN (
VALUES
('Duck'),
('Bread'),
('Milk'),
('Btuter')
) AS terms(term)
ON s.name % terms.term
ORDER BY name first try:❌ This const trimmedTerm = names.map((name) => `('${name.trim()}')`).join(',');
Product.query()
.joinRaw(`JOIN (VALUES ?) AS terms (term) ON product.name % terms.term`, [trimmedTerm])
.orderBy('name'); Result: select *
from "product"
JOIN (VALUES '(''example'),(''foobar'')') AS terms (term)
ON product.name % terms.term
order by "name" asc dangerousProduct.query()
.joinRaw(`JOIN (VALUES ${trimmedTerm}) AS terms (term) ON product.name % terms.term`)
.orderBy('name'); |
Beta Was this translation helpful? Give feedback.
Answered by
thedomeffm
Jun 12, 2025
Replies: 1 comment 1 reply
-
Ok, after some help from Copilot and Gemini I got it working: Product.query()
.joinRaw(
'JOIN unnest(?::text[]) AS terms(term) ON "product"."name" % terms.term',
[names.map((name) => name.trim())],
)
.orderBy('name', 'asc'); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
thedomeffm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, after some help from Copilot and Gemini I got it working: