Permalink
Browse files

PostgreSQL: quote bare table names

  • Loading branch information...
1 parent 5b53a06 commit 21bb0f40b075e7b878e7ae0fd6c40c9a9ad5b00a @jeremy jeremy committed Jun 7, 2008
Showing with 3 additions and 3 deletions.
  1. +3 −3 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -506,15 +506,15 @@ def create_database(name, options = {})
end
end
- execute "CREATE DATABASE #{name}#{option_string}"
+ execute "CREATE DATABASE #{quote_table_name(name)}#{option_string}"
end
# Drops a PostgreSQL database
#
# Example:
# drop_database 'matt_development'
def drop_database(name) #:nodoc:
- execute "DROP DATABASE IF EXISTS #{name}"
+ execute "DROP DATABASE IF EXISTS #{quote_table_name(name)}"
end
@@ -676,7 +676,7 @@ def pk_and_sequence_for(table) #:nodoc:
# Renames a table.
def rename_table(name, new_name)
- execute "ALTER TABLE #{name} RENAME TO #{new_name}"
+ execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}"
end
# Adds a new column to the named table.

1 comment on commit 21bb0f4

@s01ipsist

The IF EXISTS grammar clause in
DROP DATABASE [IF EXISTS] “#{name}”
was introduced in Postgresql 8.2.

Using IF EXISTS in 8.1 or prior is an SQL error.
8.1 is still in major use, it is the primary Postgresql version on Debian Etch for example.

The backwards compatible fix would seem to be to go back to the way it was done in Rails 2.0.2 using the dropdb and createdb commandline commands.

Please sign in to comment.