Skip to content

Commit 7b4ccde

Browse files
author
Justin Dell
committed
support tables with numbers in merge statements. fixes #1337
1 parent c2964ce commit 7b4ccde

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def get_raw_table_name(sql)
721721
elsif s.match?(/^\s*UPDATE\s+.*/i)
722722
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
723723
elsif s.match?(/^\s*MERGE INTO.*/i)
724-
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z_ -]+\]?\.?\[?[a-z_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
724+
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z0-9_ -]+\]?\.?\[?[a-z0-9_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
725725
else
726726
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
727727
end.strip

test/cases/schema_test_sqlserver.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
118118
it do
119119
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "MERGE INTO [with].[select notation] AS target")
120120
end
121+
122+
it do
123+
assert_equal "[with_numbers_1234]", connection.send(:get_raw_table_name, "MERGE INTO [with_numbers_1234] AS target")
124+
end
121125
end
122126

123127
describe 'CREATE VIEW statements' do

0 commit comments

Comments
 (0)