Reputation: 3745
Just like the title says, I would like to set the global default for the to_char function in Postgres. I considered this:
to_char(date_test, SELECT datestyle FROM settings)
But that seems hacky. Any better ideas?
Explanation: I want my database to present the date in a user settable format. So far, this is what I came up with. But I would appreciate a more fluent way if possible. The Postgres OUTPUT option does not support all formats.
Edit: I already formatted the date the way I want it. This is an open source app, and I want a clean way for other people to format the date. Preferably server side, since there have been requests for all server side computation to support selectable frontends.
Upvotes: 0
Views: 42
Reputation: 246153
It seems dangerous to let the user freely choose the date format, it would be better to give a choice of formats.
There is no “default format” in PostgreSQL. I would format the dates in the application rather than in the database, but you can keep the selected format in a variable and feed it to to_char
whenever you need.
Upvotes: 1