From d8f463a3b87ff9f69eef2a3ed5718b198c2072a1 Mon Sep 17 00:00:00 2001 From: Ville Lautanala Date: Tue, 25 Apr 2017 07:41:52 +0300 Subject: PostgreSQL lateral expressions Support for PostgreSQL lateral expressions. This is treated as an unary function applied to a query expression. Lateral is a separate function to provide interoperability with aliases and unions. These are also separate node types that wrap SelectStatements. The lateral option would need to be implemented in these nodes separately if lateral was an option of SelectStatement. When building the query, an alias can be given as an argument. This enables building a lateral query with an table alias without using either Nodes::TableAlias or Nodes::Lateral directly. --- test/visitors/test_postgres.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/visitors') diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 26cc721871..d3cab623c4 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -51,6 +51,20 @@ module Arel assert_equal 'SELECT DISTINCT', compile(core) end + it 'encloses LATERAL queries in parens' do + subquery = @table.project(:id).where(@table[:name].matches('foo%')) + compile(subquery.lateral).must_be_like %{ + LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') + } + end + + it 'produces LATERAL queries with alias' do + subquery = @table.project(:id).where(@table[:name].matches('foo%')) + compile(subquery.lateral('bar')).must_be_like %{ + LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') bar + } + end + describe "Nodes::Matches" do it "should know how to visit" do node = @table[:name].matches('foo%') -- cgit v1.2.3