Skip to content

Commit

Permalink
Support compounds (e.g. UNION) in conjunction with Database#values on…
Browse files Browse the repository at this point in the history
… PostgreSQL
  • Loading branch information
jeremyevans committed Feb 21, 2024
1 parent ec33f40 commit ec34d09
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Support compounds (e.g. UNION) in conjunction with Database#values on PostgreSQL (jeremyevans) (#2137)

* Support :use_advisory_lock option to Migrator.run to use advisory locks when running migrations (jeremyevans) (#2089)

* Support Database#with_advisory_lock on PostgreSQL, MySQL, and Microsoft SQL Server (jeremyevans) (#2089)
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/adapters/shared/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ module DatasetMethods

Dataset.def_sql_method(self, :delete, [['if server_version >= 90100', %w'with delete from using where returning'], ['else', %w'delete from using where returning']])
Dataset.def_sql_method(self, :insert, [['if server_version >= 90500', %w'with insert into columns override values conflict returning'], ['elsif server_version >= 90100', %w'with insert into columns values returning'], ['else', %w'insert into columns values returning']])
Dataset.def_sql_method(self, :select, [['if opts[:values]', %w'values order limit'], ['elsif server_version >= 80400', %w'with select distinct columns from join where group having window compounds order limit lock'], ['else', %w'select distinct columns from join where group having compounds order limit lock']])
Dataset.def_sql_method(self, :select, [['if opts[:values]', %w'values compounds order limit'], ['elsif server_version >= 80400', %w'with select distinct columns from join where group having window compounds order limit lock'], ['else', %w'select distinct columns from join where group having compounds order limit lock']])
Dataset.def_sql_method(self, :update, [['if server_version >= 90100', %w'with update table set from where returning'], ['else', %w'update table set from where returning']])

# Return the results of an EXPLAIN ANALYZE query as a string
Expand Down
4 changes: 4 additions & 0 deletions spec/adapters/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,10 @@ def c.exec_prepared(*); super; nil end
@db.values([[1, 2], [3, 4]]).map([:column1, :column2]).must_equal [[1, 2], [3, 4]]
end

it "should support compounds with VALUES" do
@db.values([[1, 2]]).union(@db.values([[3, 4]])).map([:column1, :column2]).must_equal [[1, 2], [3, 4]]
end

it "#values should error if given an empty array" do
proc{@db.values([])}.must_raise(Sequel::Error)
end
Expand Down

0 comments on commit ec34d09

Please sign in to comment.