Skip to content

Commit 1cef0e1

Browse files
author
Justin Dell
committed
support tables with numbers in merge statements. fixes #1337
1 parent 9cf4eaa commit 1cef0e1

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
@@ -720,7 +720,7 @@ def get_raw_table_name(sql)
720720
elsif s.match?(/^\s*UPDATE\s+.*/i)
721721
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
722722
elsif s.match?(/^\s*MERGE INTO.*/i)
723-
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z_ -]+\]?\.?\[?[a-z_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
723+
s.match(/^\s*MERGE\s+INTO\s+(\[?[a-z0-9_ -]+\]?\.?\[?[a-z0-9_ -]+\]?)\s+(AS|WITH|USING)/i)[1]
724724
else
725725
s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
726726
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)