Convert mysql command to non-platform specific commands

I have a MySQL-platform specific query

    SELECT month(from_unixtime(s.date)) AS month, count(s.id) AS blah, s.status FROM Something s WHERE s.date between unix_timestamp($blah) and unix_timestamp($blah) GROUP BY s.status, month

I used MySQL platform specific commands like month, from_unixtime and unix_timestamp.
How can I re-write this query to make it cross-platform compatible that it works on PostGre too?

Thanks,

scroll down to where it explains EXTRACT with the EPOCH option

mysql’s MONTH is done with EXTRACT as well :slight_smile:

Sorry ‘extract’ is cross-platform compatible?

i have no idea, but i know it works in PostgreSQL

by “cross-platform”, which platforms were you hoping to run it on besides PostgreSQL?

MySQL beside PostGre

i don’t think that can be done

you will have to tailor your query to the specific sql dialect of each target database system

Ok, would you please re-write my query for postgre?

no :slight_smile:

gave you enough direction that you should be able to do it yourself

There have been attempts to do that, for example Doctrine Query Language in PHP, have a look at the functions. I’m not personally fond of this monstrous ORM library so I haven’t used DQL myself. But you would need to use some sort of SQL abstraction layer in your code to make your queries work in multiple database engines.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.