# Select SQL conditions based on database

**URL:** <https://www.ruby-forum.com/t/select-sql-conditions-based-on-database/132365>\
**Category:** Rails\
**Created:** [March 19, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/select-sql-conditions-based-on-database/132365 "2008-03-19T13:46:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [March 19, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/select-sql-conditions-based-on-database/132365/1 "2008-03-19T13:46:49Z")

</div>

I’d like to have database agnostic code, however I have been  
unsuccessful writing conditions that work for both postgres and mysql  
for the following:

# postgres only

conditions = [“curtain\_at + CAST (CAST (duration AS VARCHAR) || ’  
SECOND’ AS INTERVAL) \>= ? AND curtain\_at \< ?”, Time.now, Time.now +  
2.hours]

# MySQL only

conditions = [“curtain\_at + INTERVAL duration SECOND \>= ? and  
curtain\_at \< ?”, Time.now, Time.now + 2.hours]

Concert.find(:all, :conditions =\> conditions)

Can anyone lend some SQL expertise?

As a last resort, how can I determine what the current database is so  
I can selectively set conditions?

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [March 20, 2008, 9:44pm UTC](https://www.ruby-forum.com/t/select-sql-conditions-based-on-database/132365/2 "2008-03-20T21:44:20Z")

</div>

bump
