Commit 275dc7f3 authored by Mark Chao's avatar Mark Chao

Merge branch 'id-modify-as-with-materialized' into 'master'

Inherit from Arel::Nodes::As instead of Binary

See merge request gitlab-org/gitlab!60775
parents 2c4abf28 2fc1fa98
......@@ -6,7 +6,7 @@ module Arel
class Arel::Visitors::PostgreSQL
def visit_Gitlab_Database_AsWithMaterialized(obj, collector) # rubocop:disable Naming/MethodName
collector = visit obj.left, collector
collector << " AS#{obj.expr} "
collector << " AS "
visit obj.right, collector
end
end
......
......@@ -3,18 +3,14 @@
module Gitlab
module Database
# This class is a special Arel node which allows optionally define the `MATERIALIZED` keyword for CTE and Recursive CTE queries.
class AsWithMaterialized < Arel::Nodes::Binary
class AsWithMaterialized < Arel::Nodes::As
extend Gitlab::Utils::StrongMemoize
MATERIALIZED = Arel.sql(' MATERIALIZED')
EMPTY_STRING = Arel.sql('')
attr_reader :expr
MATERIALIZED = 'MATERIALIZED '
def initialize(left, right, materialized: true)
@expr = if materialized && self.class.materialized_supported?
MATERIALIZED
else
EMPTY_STRING
if materialized && self.class.materialized_supported?
right.prepend(MATERIALIZED)
end
super(left, right)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment