I'm replying to my own post here but I think I have some valuable 
information to add -

The SQL from the 'Symbols' example below would work in PostgreSQL, see 
example 8-2:  
http://www.postgresql.org/docs/7.4/static/datatype-boolean.html.

It does not work in SQLite3 as 'it does not have a separate Boolean storage 
class':  http://www.sqlite.org/datatype3.html.

I just did this in the sqlite3 console:

sqlite> create table services ( id primary key not null, description text, 
hb_eligible boolean);
sqlite> insert into services values (1, "Grounds Maintenance", "true");
sqlite> insert into services values (2, "Laundry", "true");
sqlite> insert into services values (3, "Heating", "false");

sqlite> select * from services;
1|Grounds Maintenance|true
2|Laundry|true
3|Heating|false

sqlite> select * from services where hb_eligible;

sqlite> select * from services where hb_eligible='true';
1|Grounds Maintenance|true
2|Laundry|true

Now I am really out of my depth here. I don't know enough SQL to say who is 
doing the right thing here - the Sequel library or SQLite3. 

Should *select * from services where hb_eligible;* work in all SQL 
implementations?

Currently, the example in 'Symbols' section of Sequel documentation appear 
to be adapter-specific?

I hope this makes sense.

Regards

Ollie

On Thursday, 12 April 2012 13:27:20 UTC+1, Gruffalo wrote:
>
> Hi Simon
>
> That works and this is what I started from, but I was trying to follow 
> this document 
> http://sequel.rubyforge.org/rdoc/files/doc/querying_rdoc.html where it 
> says:
> Symbols
>
> If you have a boolean column in the database, and you want only true 
> values, you can just provide the column symbol to filter:
>
> Artist.where(:retired)
> # SELECT * FROM artists WHERE retired
>
> Which is exactly what I want but it did not work.
>
> Ollie
>
> On Thursday, 12 April 2012 09:45:00 UTC+1, Simon Arnaud wrote:
>>
>> > When I do Service.where(:hb_eligible).sql in irb it returns
>> > => "SELECT * FROM `services` WHERE `hb_eligible`"
>> > which in my limited understanding of SQL is what I want.
>>
>> It seems you expect the SQL "WHERE" clause to behave like Ruby "if",
>> and it does not.
>>
>> Try:
>> Service.where(:hb_eligible => true)
>>
>> Simon
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/FjpuBuR5b3wJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to