Last Update: 2024-01-04 11:10:16 -0800

The duplicate_columns_handler extension allows you to customize handling of duplicate column names in your queries on a per-database or per-dataset level.

For example, you may want to raise an exception if you join 2 tables together which contains a column that will override another columns.

To use the extension, you need to load the extension into the database:

DB.extension :duplicate_columns_handler

or into individual datasets:

ds = DB[:items].extension(:duplicate_columns_handler)

If the Database option :on_duplicate_columns is set, it configures how this extension works. The value should be # or any object that responds to :call.

on_duplicate_columns: :raise # or 'raise'
on_duplicate_columns: :warn # or 'warn'
on_duplicate_columns: :ignore # or anything unrecognized
on_duplicate_columns: lambda{|columns| arbitrary_condition? ? :raise : :warn}

You may also configure duplicate columns handling for a specific dataset:

ds.on_duplicate_columns{|columns| arbitrary_condition? ? :raise : :warn}
ds.on_duplicate_columns(lambda{|columns| arbitrary_condition? ? :raise : :warn})

If :raise or ‘raise’ is specified, a Sequel::DuplicateColumnError is raised. If :warn or ‘warn’ is specified, you will receive a warning via warn. If a callable is specified, it will be called. For other values, duplicate columns are ignored (Sequel’s default behavior) If no on_duplicate_columns is specified, the default is :warn.

Related module: Sequel::DuplicateColumnsHandler