can anyone please tell me how to write query in select_value.
I have tried,
ActiveRecord::Base.connection.select_value("select count(*) from leave_details where status= 'Pending' and 'employeedetails_id'=25")
but it showing error
invalid input syntax for integer: "employeedetails_id".
I am using PostgreSQL.
Single quotes are used to quote strings in PostgreSQL (and every other SQL database that even pretends to respect the SQL standard) so you’re saying something like this:
when you do this:
and that doesn’t make any sense: you can’t compare strings and integers without an explicit type cast. You don’t need to quote that identifier at all:
If you even do need to quote an identifier (perhaps it is case sensitive or contains spaces), then you’d use double quotes with PostgreSQL.
Apparently you created your column as
"EmployeeDetails_id"so that it is case sensitive. That means that you always have to use that case and you always have to double quote it:I’d recommend reworking your table to not use mixed case identifiers:
This is going to trip you up over and over again.