Method: Sequel::Dataset#merge_sql

Defined in:
lib/sequel/dataset/sql.rb

#merge_sqlObject

The SQL to use for the MERGE statement.

Raises:

[View source]

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sequel/dataset/sql.rb', line 94

def merge_sql
  raise Error, "This database doesn't support MERGE" unless supports_merge?
  if sql = opts[:sql]
    return static_sql(sql)
  end
  if sql = cache_get(:_merge_sql)
    return sql
  end
  source, join_condition = @opts[:merge_using]
  raise Error, "No USING clause for MERGE" unless source
  sql = @opts[:append_sql] || sql_string_origin

  select_with_sql(sql)
  sql << "MERGE INTO "
  source_list_append(sql, @opts[:from])
  sql << " USING "
  identifier_append(sql, source)
  sql << " ON "
  literal_append(sql, join_condition)
  _merge_when_sql(sql)
  cache_set(:_merge_sql, sql) if cache_sql?
  sql
end