Last Update: 2017-08-01 08:12:00 -0700

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)

A database option is introduced: :on_duplicate_columns. It accepts a Symbol or any object that responds to :call.

on_duplicate_columns: :raise
on_duplicate_columns: :warn
on_duplicate_columns: :ignore
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 is specified, a Sequel::DuplicateColumnError is raised. If :warn is specified, you will receive a warning via warn. If a callable is specified, it will be called. If no on_duplicate_columns is specified, the default is :warn.

Related module: Sequel::DuplicateColumnsHandler