instance method
table_exists?
Ruby on Rails 3.0.20
Since v3.0.20 Last seen in v3.2.22.5Signature
table_exists?(name)
No documentation comment.
Parameters
-
namereq
Source
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 621
def table_exists?(name)
name = name.to_s
schema, table = name.split('.', 2)
unless table # A table was provided without a schema
table = schema
schema = nil
end
if name =~ /^"/ # Handle quoted table names
table = name
schema = nil
end
query(<<-SQL).first[0].to_i > 0
SELECT COUNT(*)
FROM pg_tables
WHERE tablename = '#{table.gsub(/(^"|"$)/,'')}'
AND schemaname = #{schema ? "'#{schema}'" : "ANY (current_schemas(false))"}
SQL
end
Defined in activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb line 621
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter