Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In PostgreSQL, allow spaces in table names without schema #26722

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ module Utils # :nodoc:
# * <tt>"schema_name".table_name</tt>
# * <tt>"schema.name"."table name"</tt>
def extract_schema_qualified_name(string)
schema, table = string.scan(/[^".\s]+|"[^"]*"/)
if table.nil?
table = schema
schema = nil
if string.include?(".")
schema, table = string.scan(/[^".\s]+|"[^"]*"/)
if table.nil?
table = schema
schema = nil
end
PostgreSQL::Name.new(schema, table)
else
PostgreSQL::Name.new(nil, string)
end
PostgreSQL::Name.new(schema, table)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions activerecord/test/cases/adapters/postgresql/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ class PostgreSQLUtilsTest < ActiveRecord::PostgreSQLTestCase
def test_extract_schema_qualified_name
{
%(table_name) => [nil,"table_name"],
%("table_name") => [nil,"table_name"],
%("table.name") => [nil,"table.name"],
%(schema.table_name) => %w{schema table_name},
%("schema".table_name) => %w{schema table_name},
%(schema."table_name") => %w{schema table_name},
%("schema"."table_name") => %w{schema table_name},
%("even spaces".table) => ["even spaces","table"],
%(spaces table only) => [nil,"spaces table only"],
%("spaces table only") => [nil,"spaces table only"],
%(schema."table.name") => ["schema", "table.name"]
}.each do |given, expect|
assert_equal Name.new(*expect), extract_schema_qualified_name(given)
Expand Down