@@ -232,10 +232,18 @@ def supports_insert_on_conflict?
232232 alias supports_insert_on_duplicate_update? supports_insert_on_conflict?
233233 alias supports_insert_conflict_target? supports_insert_on_conflict?
234234
235+ def supports_virtual_columns?
236+ database_version >= 12_00_00 # >= 12.0
237+ end
238+
235239 def supports_identity_columns? # :nodoc:
236240 database_version >= 10_00_00 # >= 10.0
237241 end
238242
243+ def supports_nulls_not_distinct?
244+ database_version >= 15_00_00 # >= 15.0
245+ end
246+
239247 def index_algorithms
240248 { concurrently : 'CONCURRENTLY' }
241249 end
@@ -632,17 +640,19 @@ def column_name_for_operation(operation, node)
632640 # - format_type includes the column size constraint, e.g. varchar(50)
633641 # - ::regclass is a function that gives the id for a table name
634642 def column_definitions ( table_name )
635- select_rows ( <<~SQL , 'SCHEMA' )
636- SELECT a.attname, format_type(a.atttypid, a.atttypmod),
637- pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
638- c.collname, col_description(a.attrelid, a.attnum) AS comment
639- FROM pg_attribute a
640- LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
641- LEFT JOIN pg_type t ON a.atttypid = t.oid
642- LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
643- WHERE a.attrelid = #{ quote ( quote_table_name ( table_name ) ) } ::regclass
644- AND a.attnum > 0 AND NOT a.attisdropped
645- ORDER BY a.attnum
643+ query ( <<~SQL , "SCHEMA" )
644+ SELECT a.attname, format_type(a.atttypid, a.atttypmod),
645+ pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
646+ c.collname, col_description(a.attrelid, a.attnum) AS comment,
647+ #{ supports_identity_columns? ? 'attidentity' : quote ( '' ) } AS identity,
648+ #{ supports_virtual_columns? ? 'attgenerated' : quote ( '' ) } as attgenerated
649+ FROM pg_attribute a
650+ LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
651+ LEFT JOIN pg_type t ON a.atttypid = t.oid
652+ LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
653+ WHERE a.attrelid = #{ quote ( quote_table_name ( table_name ) ) } ::regclass
654+ AND a.attnum > 0 AND NOT a.attisdropped
655+ ORDER BY a.attnum
646656 SQL
647657 end
648658
0 commit comments