Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Make PostgreSQL do bitwise xor instead of exponentiation for ^ operator

One of Sequel's jobs is to provide an interface that maps ruby
syntax to get the same semantics regardless of database (as much
as possible).  Ruby's ^ operator does bitwise xor, but PostgreSQL's
^ operator does exponentiation.  This commit makes Sequel use the
PostgreSQL bitwise xor operator (#) on PostgreSQL, so that you will
get similar results as on other databases.

This breaks backwards compatibility for people currently using the
^ operator on PostgreSQL.  In the meantime, you can probably switch
to using the power function.
  • Loading branch information...
1 parent c1a6b68 commit 1acde327810aaac09186b2eaf24f2f06c82f199e @jeremyevans committed
Showing with 13 additions and 0 deletions.
  1. +2 −0  CHANGELOG
  2. +11 −0 lib/sequel/adapters/shared/postgres.rb
@@ -1,5 +1,7 @@
=== HEAD
+* Make PostgreSQL do bitwise xor instead of exponentiation for ^ operator (jeremyevans)
* Fix handling of tinyint(1) columns when connecting to MySQL via JDBC (jeremyevans)
* Handle arrays of two element arrays as filter hash values automatically (jeremyevans)
11 lib/sequel/adapters/shared/postgres.rb
@@ -674,6 +674,17 @@ def analyze
+ # Handle converting the ruby xor operator (^) into the
+ # PostgreSQL xor operator (#).
+ def complex_expression_sql(op, args)
+ case op
+ when :^
+ "(#{literal(} # #{literal(})"
+ else
+ super
+ end
+ end
# Disable the use of INSERT RETURNING, even if the server supports it
def disable_insert_returning

0 comments on commit 1acde32

Please sign in to comment.
Something went wrong with that request. Please try again.