I use derby and PostgreSQL and they have different syntaxes for aggregating over years and months (“YEAR(timestamp)” vs. “extract(year from timestamp) as year” (both result in a column name year or YEAR to be used in the query).
Derby do it this way:
select sum(t.transaction_amount), extract(year from t.transaction_time) as year, extract(month from t.transaction_time) as month from transactions t join transaction_types tt on tt.transaction_type_id=t.transaction_type_id join accounts a on a.account_id=t.account_id where tt.transaction_is_work and a.username=? group by extract(year from t.transaction_time), extract(month from t.transaction_time) order by extract(year from t.transaction_time), extract(month from t.transaction_time)
What's the best way to create a view conditionally based on the dbms used?
Is there some kind of if-then-else logic? (I have googled, but haven't found)
The only way I can think about is to have two separate changesets for creating the same view with a precondition on the dbms used...?
Also, instead of selecting on dbms, I would have preferred to select on capability so that instead of creating a view just for derby I would create a view for all dbms'es that follow the same syntax (and ditto for PostgreSQL). Is this possible?