lundi 23 février 2015

Concatenate an underscore with a string in Postgresql

I'm trying to build up a string that will look like this in Postgres 9.3.



2015_2_23_10


It's the current year, month, day, and hour, separated by underscores.


Here's the query that creates the string



select
cast(extract(year from now()) as text) || '_' ||
cast(extract(month from now()) as text) || '_' ||
cast(extract(day from now()) as text) || '_' ||
cast(extract(hour from now()) as text);


However, the underscores get turned into spaces. I also tried prefacing the underscores with an E, like so ...|| E'_' || ..., but that didn't work either.


Aucun commentaire:

Enregistrer un commentaire