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

Search columns of type "integer" on PostgreSQL #17

Open
dr-gonzo opened this issue Jul 22, 2015 · 6 comments
Open

Search columns of type "integer" on PostgreSQL #17

dr-gonzo opened this issue Jul 22, 2015 · 6 comments
Labels
Milestone

Comments

@dr-gonzo
Copy link

How can I search the ID column of a table in a postgresql database with this gem? There is nothing like "cast_to_text" present so the request on an integer column always fails because of the lower() function.

PG::UndefinedFunction: ERROR: function lower(integer) does not exist LINE 1: ...s"."id", "accounts"."name" FROM "accounts" WHERE (LOWER(acco... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. : SELECT accounts.id, "accounts"."id", "accounts"."name" FROM "accounts" WHERE (LOWER(accounts.id) ILIKE '10%') ORDER BY LOWER(accounts.id) ASC LIMIT 20

@dr-gonzo
Copy link
Author

Ok I wrote an implementation of CAST(.. AS text). Find it here: https://github.com/dr-gonzo/rails-jquery-autocomplete/blob/master/lib/rails-jquery-autocomplete/orm/active_record.rb

If I can find the time I'll write some tests and file a pull request. Great gem btw, thanks!

@bigtunacan
Copy link
Collaborator

@dr-gonzo, did you test against master, or only the most recently released official gem?

It sounds like the issue you are mentioning here may have been fixed on master with this other pull request, #15 ?

@dr-gonzo
Copy link
Author

Hi, I used master and just tested again to make sure. Besides I don't see how it should be possible to solve the problem of using the LOWER() function in an SQL statement on an integer type column through jQuery.

Both statements in the active_record.rb:
order || "LOWER(#{table_prefix}#{method}) ASC"
["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]

must necessarily fail on every integer type database column, mustn't it?

@bigtunacan bigtunacan added the bug label Aug 19, 2015
@bigtunacan bigtunacan added this to the 1.0.3 milestone Aug 19, 2015
@bigtunacan bigtunacan modified the milestones: 1.0.4, 1.0.3 Oct 28, 2015
@bigtunacan
Copy link
Collaborator

@dr-gonzo It's been awhile since you added this pull request. I just wanted to send you a quick update. I haven't pulled this in yet as it doesn't work correctly as it is.

The def active_record_get_autocomplete_order(method, options, model=nil, cast_text) method model parameter is optional. Adding a required parameter after an optional parameter would break backwards compatibility.

The casting is being blanket applied, but does not work with all databases (for example it is incompatible with SQL Server); so some checks should be applied first.

I do plan to update it prior to the next release.

@dr-gonzo
Copy link
Author

Hey, thanks for the update. I agree to your arguments and look forward to the upcomming release.

@daande
Copy link

daande commented Dec 13, 2015

Is there any update on this as I am currently experiencing this problem?

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

No branches or pull requests

3 participants