class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
def column_definitions(table_name)
Experimental RBS support (using type sampling data from the type_fusion project).
def column_definitions: (String table_name) -> untyped
This signature was generated using 1 sample from 1 application.
- format_type includes the column size constraint, e.g. varchar(50)
Query implementation notes:
take the first match from the schema search path.
If the table name is not prefixed with a schema, the database will
ORDER BY column.num
AND NOT column.is_dropped
AND column.num > 0
WHERE column.table_id = get_table_id('table_name')
AND column.num = default.column_num
ON column.table_id = default.table_id
FROM column LEFT JOIN default
SELECT column.name, column.type, default.value, column.comment
The underlying query is roughly:
Returns the list of a table's column names, data types, and default values.
def column_definitions(table_name) query(<<~SQL, "SCHEMA") SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, c.collname, col_description(a.attrelid, a.attnum) AS comment, #{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum LEFT JOIN pg_type t ON a.atttypid = t.oid LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation WHERE a.attrelid = #{quote(quote_table_name(table_name))}::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum SQL end