From 59fe3c7df9cfb135547132e3bc99ddf3fddefc58 Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Sun, 16 Aug 2026 12:47:39 +0100 Subject: [PATCH 1/2] Fix SQL emitted for limited compound query Previously SQL like "... = $2LIMIT $3", was emitted, resulting in an error like: > trailing junk after parameter at or near "$2LIMIT" (PQ::PQError) --- spec/interro_spec.cr | 9 +++++++++ src/query_builder.cr | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/interro_spec.cr b/spec/interro_spec.cr index 280efee..1e0d451 100644 --- a/spec/interro_spec.cr +++ b/spec/interro_spec.cr @@ -806,6 +806,15 @@ describe Interro do users.should_not contain excluded end + it "can limit compound queries" do + Array.new(2) { create_user(name: "Limit LHS") } + Array.new(2) { create_user(name: "Limit RHS") } + + users = (query.with_name("Limit LHS") | query.with_name("Limit RHS")).first(3).to_a + + users.size.should eq 3 + end + describe "subqueries" do it "queries on membership in a set" do included = create_user(email: "included-#{UUID.random}") diff --git a/src/query_builder.cr b/src/query_builder.cr index 04815f7..31e22ca 100644 --- a/src/query_builder.cr +++ b/src/query_builder.cr @@ -1052,7 +1052,7 @@ module Interro str << ' ' << @combinator << ' ' str << rhs if @limit - str << "LIMIT $" << (arg_count += 1) + str << " LIMIT $" << (arg_count += 1) end end end From fa66bb1c9d004e5097ed0066a99d558f1903872b Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Sun, 16 Aug 2026 12:47:39 +0100 Subject: [PATCH 2/2] Fix SQL emitted for INTERSECT query The & combinator used the wrong keyword, resulting in an error like: > syntax error at or near "INTERSECTION" (PQ::PQError) --- spec/interro_spec.cr | 10 ++++++++++ src/query_builder.cr | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/interro_spec.cr b/spec/interro_spec.cr index 1e0d451..7d7daca 100644 --- a/spec/interro_spec.cr +++ b/spec/interro_spec.cr @@ -806,6 +806,16 @@ describe Interro do users.should_not contain excluded end + it "can run INTERSECT queries" do + both = create_user(name: "Both") + only_lhs = create_user(name: "Both", email: "lhs-only-#{UUID.random}@example.com") + + users = (query.with_name("Both") & query.with_id(both.id)).to_a + + users.should contain both + users.should_not contain only_lhs + end + it "can limit compound queries" do Array.new(2) { create_user(name: "Limit LHS") } Array.new(2) { create_user(name: "Limit RHS") } diff --git a/src/query_builder.cr b/src/query_builder.cr index 31e22ca..8dd7d3a 100644 --- a/src/query_builder.cr +++ b/src/query_builder.cr @@ -258,7 +258,7 @@ module Interro end def &(other : self) : CompoundQuery - CompoundQuery.new(self, "INTERSECTION", other, connection(CONFIG.read_db)) + CompoundQuery.new(self, "INTERSECT", other, connection(CONFIG.read_db)) end def -(other : self) : CompoundQuery