Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL support #5

Closed
le0pard opened this issue Feb 26, 2017 · 10 comments
Closed

PostgreSQL support #5

le0pard opened this issue Feb 26, 2017 · 10 comments

Comments

@le0pard
Copy link

le0pard commented Feb 26, 2017

Hello. Looks like this gem will not work in PostgreSQL, only MySQL (no support for ORDER BY FIELD()). You can use something like this for PostgreSQL:

SELECT foo.* FROM foo                                           
JOIN (SELECT id.val, row_number() over() FROM (VALUES(3),(2),(6),(1),(4)) AS
id(val)) AS id
ON (foo.catalog_id = id.val) ORDER BY row_number;

example:

$ SELECT * FROM users WHERE id IN (3,2,1) ORDER BY FIELD(id, 3,2,1);
ERROR:  function field(integer, integer, integer, integer) does not exist
LINE 1: SELECT * FROM users WHERE id IN (3,2,1) ORDER BY FIELD(id, 3...
                                                         ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

$ SELECT users.* FROM users JOIN (SELECT id.val, row_number() over() FROM (VALUES(3),(2),(1)) AS id(val)) AS id ON (users.id = id.val) ORDER BY row_number;

id |      name
----+-----------------
  2 |
  1 | Alexey Vasiliev
(2 rows)
@khiav223577
Copy link
Owner

khiav223577 commented Feb 28, 2017

Thanks for the hint :)
I'll take a look at it soon.
Or would you mind submitting a PR?

@le0pard
Copy link
Author

le0pard commented Feb 28, 2017

@khiav223577 sorry, don't have time right now :(

@khiav223577
Copy link
Owner

It's OK. Thanks for your hint again :)

@khiav223577
Copy link
Owner

Just submitted a PR for this. - #7

@khiav223577
Copy link
Owner

khiav223577 commented Mar 28, 2017

1.1.0 was released. It supports PostgreSQL now.

@darcang
Copy link

darcang commented May 8, 2019

@khiav223577 Hey, is there any solution to support pgsql uuid type?

@khiav223577
Copy link
Owner

@darcang
What is your error message of using uuid type?
operator does not exist: uuid = text?

@darcang
Copy link

darcang commented May 9, 2019

@khiav223577 yeah, i got this working for PG >= 9.5 using

User.where(id: ids)
  .order(Arel.sql("array_position(ARRAY['#{ids.join("','")}']::uuid[], users.id)"))

@khiav223577
Copy link
Owner

Hi, @darcang
I released 1.3.0 to support psql uuid type.
See the implementation here: #18

@darcang
Copy link

darcang commented May 13, 2019

@khiav223577 nice, great thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants