On Wed, Nov 30, 2022 at 11:19 PM 'Maria Fradkin' via sequel-talk <
sequel-talk@googlegroups.com> wrote:

> Hello,
>
> I have discovered one additional problem related to the partitioned tables
> in Postgres. We use unique index and constraint definitions to handle
> insert on conflict behaviour in our code, but for some reason we cannot
> automatically detect indexes for partitioned tables. Here is the example:
> My table is partitioned by hash on some_id column, I have few partitions
> attached
> some_table_hash_p1
> some_table_hash_p2
> ...
> some_table_hash_p16
> And we have indexes both unique and not unique on this table.
> When I try SomeTable.db.indexes(:some_table, include_partial: true) I am
> getting {}
> On the same structure on the table but without partitioning I see all
> indexes as defined in DB
> {:some_table_col1_id_col3_hash_col2_id_index=>{:columns=>[:col1_id,
> :col3_hash, :col2_id], :unique=>false, :deferrable=>nil},
> :some_table_col1_id_col3_id_col2_id_index=>{:columns=>[:col1_id, :col3_id,
> :col2_id], :unique=>false, :deferrable=>nil}, ... }
>
> Can you please advise me again how to fix this issue with an actual model
> table?
>

Looks like partitioned indexes use a different reltype.  Can you try this
patch?:

 diff --git a/lib/sequel/adapters/shared/postgres.rb
b/lib/sequel/adapters/shared/postgres.rb
index bc9fc68a4..3ef326f4b 100644
--- a/lib/sequel/adapters/shared/postgres.rb
+++ b/lib/sequel/adapters/shared/postgres.rb
@@ -919,7 +919,7 @@ module Sequel
             join(Sequel[:pg_attribute].as(:att),
:attrelid=>Sequel[:tab][:oid], :attnum=>attnums).
             left_join(Sequel[:pg_constraint].as(:con),
:conname=>Sequel[:indc][:relname]).
             where{{
-              indc[:relkind]=>'i',
+              indc[:relkind]=>%w'i I',
               ind[:indisprimary]=>false,
               :indexprs=>nil,
               :indisvalid=>true}}.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSf2T48BgqOmQpyikjdfqsAkU1aTMnmS%3DLHDg_iz-PuExg%40mail.gmail.com.

Reply via email to