From d532b7ee430c5d0c412ab9f1a5e0dd3ebc47f86b Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Thu, 20 Jan 2011 12:56:08 -0700 Subject: Add support for WITH and UNION PostgreSQL WITH RECURSIVE support Make WITH be a unary node --- lib/arel/visitors/to_sql.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/arel/visitors') diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index d5534384f8..f3c8710068 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -129,6 +129,8 @@ eowarn def visit_Arel_Nodes_SelectStatement o [ + (visit(o.with) if o.with), + (visit(o.with_recursive) if o.with_recursive), o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join, ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), (visit(o.limit) if o.limit), @@ -149,6 +151,22 @@ eowarn ].compact.join ' ' end + def visit_Arel_Nodes_With o + "WITH #{visit o.children}" + end + + def visit_Arel_Nodes_WithRecursive o + "WITH RECURSIVE #{visit o.children}" + end + + def visit_Arel_Nodes_Union o + "( #{visit o.left} UNION #{visit o.right} )" + end + + def visit_Arel_Nodes_UnionAll o + "( #{visit o.left} UNION ALL #{visit o.right} )" + end + def visit_Arel_Nodes_Having o "HAVING #{visit o.expr}" end -- cgit v1.2.3