method
column_definitions
v6.1.7.7 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
column_definitions(table_name)
private
Returns the list of a table’s column names, data types, and default values.
The underlying query is roughly:
SELECT column.name, column.type, default.value, column.comment FROM column LEFT JOIN default ON column.table_id = default.table_id AND column.num = default.column_num WHERE column.table_id = get_table_id('table_name') AND column.num > 0 AND NOT column.is_dropped ORDER BY column.num
If the table name is not prefixed with a schema, the database will take the first match from the schema search path.
Query implementation notes:
- format_type includes the column size constraint, e.g. varchar(50) - ::regclass is a function that gives the id for a table name