File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1757,7 +1757,7 @@ def index_definition_sql(table_name, index)
17571757 index_type = :gist
17581758 end
17591759
1760- "CREATE #{ unique } INDEX#{ ' CONCURRENTLY' if index [ :concurrently ] } #{ if_not_exists } #{ quote_identifier ( index_name ) } ON #{ quote_schema_table ( table_name ) } #{ "USING #{ index_type } " if index_type } #{ expr } #{ " INCLUDE #{ literal ( Array ( index [ :include ] ) ) } " if index [ :include ] } #{ nulls_distinct } #{ " TABLESPACE #{ quote_identifier ( index [ :tablespace ] ) } " if index [ :tablespace ] } #{ filter } "
1760+ "CREATE #{ unique } INDEX#{ ' CONCURRENTLY' if index [ :concurrently ] } #{ if_not_exists } #{ quote_identifier ( index_name ) } ON#{ ' ONLY' if index [ :only ] } #{ quote_schema_table ( table_name ) } #{ "USING #{ index_type } " if index_type } #{ expr } #{ " INCLUDE #{ literal ( Array ( index [ :include ] ) ) } " if index [ :include ] } #{ nulls_distinct } #{ " TABLESPACE #{ quote_identifier ( index [ :tablespace ] ) } " if index [ :tablespace ] } #{ filter } "
17611761 end
17621762
17631763 # Setup datastructures shared by all postgres adapters.
Original file line number Diff line number Diff line change @@ -299,6 +299,7 @@ def has_column?(name)
299299 # :opclass :: Set an opclass to use for all columns (per-column opclasses require
300300 # custom SQL).
301301 # :tablespace :: Specify tablespace for index.
302+ # :only :: Create index only for given table, not for any child tables (PostgreSQL 11+)
302303 #
303304 # Microsoft SQL Server specific options:
304305 #
Original file line number Diff line number Diff line change @@ -1641,6 +1641,15 @@ def before_create
16411641 @db . add_index :atest , :a , :tablespace => :pg_default
16421642 end
16431643
1644+ it "should support creating indexes with ONLY option" do
1645+ @db . create_table ( :atest , partition_by : :id , :partition_type => :range ) { Integer :id }
1646+ @db . create_table ( :btest , partition_of : :atest ) { from 1 ; to 3 }
1647+ @db . add_index :atest , :id , :only => true
1648+
1649+ @db . indexes ( :atest , :include_invalid => true ) . size . must_equal 1
1650+ @db . indexes ( :btest , :include_invalid => true ) . must_be_empty
1651+ end if DB . server_version >= 110000
1652+
16441653 it "#lock should lock table if inside a transaction" do
16451654 @db . transaction { @d . lock ( 'EXCLUSIVE' ) ; @d . insert ( :name => 'a' ) }
16461655 end
You can’t perform that action at this time.
0 commit comments