Returns true if table exists. If the schema is not specified as part of
name then it will only find tables
within the current schema search path (regardless of permissions to access
tables
in other schemas)
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 791
def table_exists?(name)
schema, table = Utils.extract_schema_and_table(name.to_s)
return false unless table
binds = [[nil, table]]
binds << [nil, schema] if schema
exec_query( SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind in ('v','r') AND c.relname = $1 AND n.nspname = #{schema ? '$2' : 'ANY (current_schemas(false))'}, 'SCHEMA', binds).rows.first[0].to_i > 0
end