pennylane-hq / activerecord-adapter-redshift

Other
6 stars 27 forks source link

Not possible to use "insert_all" #39

Open dbackeus opened 1 day ago

dbackeus commented 1 day ago

Attempting to use the insert_all API from ActiveRecord results in: ArgumentError: ActiveRecord::ConnectionAdapters::RedshiftAdapter does not support skipping duplicates

Attempting to bypass the uniqueness check by passing unique_by: [] results in: ArgumentError: ActiveRecord::ConnectionAdapters::RedshiftAdapter does not support :unique_by

It makes sense that Redshift can't support skipping duplicates. But perhaps it would be possible to bypass the duplicate check altogether.

Any thoughts or suggestions for workarounds?

quentindemetz commented 18 hours ago

I've only used this gem to perform read queries, and never to write 🤷🏻. What behavior do you expect exactly? Do you want to ignore the concept of duplicates and insert them anyway? Or do you want a best-effort to try and minimize inserting duplicates by running a SELECT query first?

dbackeus commented 14 hours ago

What would make sense to me is to allow insert_all but without any duplicates protection.

According to the insert_all documentation the default behaviour is to use all "unique indexes" to avoid duplicates, but since Redshift doesn't support unique indexes the obvious outcome should be that it runs without any duplicate detection.

I also think explicitly sending unique_by with a non empty Array should raise an ArgumentError to make it clear that duplicate protection also can't be forced on (potentially this could be evolved to use a SELECT statement but seems YAGNI at this point).