instance method fetch_column_definitions

Ruby on Rails edge

Since edge Private — implementation detail, not part of the public API

Signature

fetch_column_definitions(tables)

No documentation comment.

Parameters

tables req
Source
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 1286
        def fetch_column_definitions(tables)
          fetch_by_schema(tables) do |schema, group|
            rows = query_rows(<<~SQL)
              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_identity_columns? ? 'attidentity' : quote('')} AS identity,
                     #{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated,
                     r.relname
              FROM (
                SELECT DISTINCT ON (cls.relname) cls.oid, cls.relname
                FROM pg_class cls
                JOIN pg_namespace n ON n.oid = cls.relnamespace
                WHERE n.nspname = #{schema}
                  AND cls.relname IN (#{quoted_table_names(group)})
                ORDER BY cls.relname, array_position(current_schemas(false), n.nspname)
              ) r
              JOIN pg_attribute a ON a.attrelid = r.oid
              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.attnum > 0 AND NOT a.attisdropped
              ORDER BY r.relname, a.attnum
            SQL
            by_name = rows.group_by(&:last)

            group.index_with do |table|
              fields = rows_for(by_name, table)

              fields.empty? ? column_definitions(table) : fields
            end
          end
        end

Defined in activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb line 1286 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close