# Select SQL conditions based on database

**URL:** <https://discuss.rubyonrails.org/t/select-sql-conditions-based-on-database/26554>\
**Category:** rubyonrails-talk\
**Created:** [March 19, 2008, 12:45pm UTC](https://discuss.rubyonrails.org/t/select-sql-conditions-based-on-database/26554 "2008-03-19T12:45:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gsterndale](https://discuss.rubyonrails.org/u/gsterndale)\
**Post date:** [March 19, 2008, 12:45pm UTC](https://discuss.rubyonrails.org/t/select-sql-conditions-based-on-database/26554/1 "2008-03-19T12:45:43Z")

</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://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gsterndale](https://discuss.rubyonrails.org/u/gsterndale)\
**Post date:** [March 20, 2008, 8:43pm UTC](https://discuss.rubyonrails.org/t/select-sql-conditions-based-on-database/26554/2 "2008-03-20T20:43:36Z")

</div>

bump
