method
table_exists?
v3.2.13 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
table_exists?(name)public
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 787
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 = '#{table.gsub(/(^"|"$)/,'')}' AND n.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}, 'SCHEMA').rows.first[0].to_i > 0
end Related methods
- Instance methods
- active?
- adapter_name
- add_column
- begin_db_transaction
- change_column
- change_column_default
- change_column_null
- clear_cache!
- client_min_messages
- client_min_messages=
- columns
- commit_db_transaction
- create_database
- create_savepoint
- current_database
- current_schema
- default_sequence_name
- disable_referential_integrity
- disconnect!
- distinct
- drop_database
- encoding
- escape_bytea
- exec_delete
- exec_query
- exec_update
- execute
- explain
- index_name_length
- indexes
- insert_sql
- native_database_types
- outside_transaction?
- pk_and_sequence_for
- primary_key
- query
- quote
- quote_column_name
- quote_string
- quote_table_name
- quoted_date
- reconnect!
- recreate_database
- release_savepoint
- remove_index!
- rename_column
- rename_index
- rename_table
- reset!
- reset_pk_sequence!
- result_as_array
- rollback_db_transaction
- rollback_to_savepoint
- schema_exists?
- schema_search_path
- schema_search_path=
- select_rows
- serial_sequence
- session_auth=
- set_standard_conforming_strings
- sql_for_insert
- substitute_at
- supports_ddl_transactions?
- supports_disable_referential_integrity?
- supports_explain?
- supports_index_sort_order?
- supports_insert_with_returning?
- supports_migrations?
- supports_primary_key?
- supports_savepoints?
- supports_statement_cache?
- table_alias_length
- table_exists?
- tables
- type_cast
- type_to_sql
- unescape_bytea
- update_sql
- Class methods
- new
- Protected methods
-
postgresql_version -
translate_exception - Private methods
-
column_definitions -
configure_connection -
connect -
exec_cache -
exec_no_cache -
extract_pg_identifier_from_name -
extract_table_ref_from_insert_sql -
last_insert_id -
prepare_statement -
select -
select_raw -
sql_key -
table_definition