Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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...
commit 1acde327810aaac09186b2eaf24f2f06c82f199e 1 parent c1a6b68
Jeremy Evans authored
Showing with 13 additions and 0 deletions.
  1. +2 −0  CHANGELOG
  2. +11 −0 lib/sequel/adapters/shared/postgres.rb
2  CHANGELOG
View
@@ -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
View
@@ -674,6 +674,17 @@ def analyze
explain(:analyze=>true)
end
+ # Handle converting the ruby xor operator (^) into the
+ # PostgreSQL xor operator (#).
+ def complex_expression_sql(op, args)
+ case op
+ when :^
+ "(#{literal(args.at(0))} # #{literal(args.at(1))})"
+ else
+ super
+ end
+ end
+
# Disable the use of INSERT RETURNING, even if the server supports it
def disable_insert_returning
clone(:disable_insert_returning=>true)
Please sign in to comment.
Something went wrong with that request. Please try again.