Skip to content

Instantly share code, notes, and snippets.

@whatcould
Forked from heijmerikx/gist:1261118
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatcould/5a7c6c28e757544744e4 to your computer and use it in GitHub Desktop.
Save whatcould/5a7c6c28e757544744e4 to your computer and use it in GitHub Desktop.
MySQL FIND_IN_SET to Postgresql...
def self.order(ids)
# The postgresql way
update_all(["position = STRPOS(?, ','||id||',')", ",#{ids.join(',')},"])
# the mysql way
# update_all(['position = FIND_IN_SET(id, ?)', ids.join(',')])
end
@whatcould
Copy link
Author

The original gist had a strange {:id => ids} parameter that didn't seem necessary (and caused an error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment