Rewriting CONCAT_WS to Postgres
11/18/2010I have noticed a couple complaints about converting MySQL's CONCAT and CONCAT_WS functions to Postgres .
Naturally, such a commonly used function must work, so I rewrote it with the parser:
select concat_ws(',', `asdf`, 'w00t', somecolumn)
from mysql.db;
Is rewritten to:
select ARRAY_TO_STRING(ARRAY["asdf", 'w00t', somecolumn], ',')
from mysql.db;
It seems the Postgres way is uglier but it is far more versatile than CONCAT_WS. Not only does Postgres have array types, but it can handle many more cases than just concatenating elements.
Pgify: https://github.com/mrj0/pgify
Even more awesome is coming soon.