pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16238: Function " to_char(timestamp, text) " doesn't work properly
4+ messages / 4 participants
[nested] [flat]
* BUG #16238: Function " to_char(timestamp, text) " doesn't work properly
@ 2020-01-30 11:49 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 4+ messages in thread
From: PG Bug reporting form @ 2020-01-30 11:49 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: memnik@hotmail.com
The following bug has been logged on the website:
Bug reference: 16238
Logged by: Nick Memos
Email address: memnik@hotmail.com
PostgreSQL version: 10.7
Operating system: Windows 10
Description:
Hello,
I have created a table with a json column. Where in this json i have some
details for each day of the week. It is something like this '{"Monday":
13,"Tuesday": 13,"Wednesday": 13, "Thursday ": 12, "Friday": 13,"Saturday":
13,"Sunday": 13}'::json.
So, when i try to get the information for each day by this way: '{"Monday":
13,"Tuesday": 13,"Wednesday": 13, "Thursday ": 12, "Friday": 13,"Saturday":
13,"Sunday": 13}'::json->>to_char(current_timestamp,'Day') , i don't get the
results for all days. As i noticed the problem is that the function "
to_char(timestamp, text) " doesn't work properly. For example this query "
select to_char('2020-01-29'::date,'Day') " give me this result "Wednesday",
but this query " select to_char('2020-01-31'::date,'Day') " give me this
result "Friday ".
So, i guess it is not right to have days with many spaces as a result and
some days without any space.
Now i will user trim() function but it is better to fix that if it is
possible.
Thanks!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #16238: Function " to_char(timestamp, text) " doesn't work properly
@ 2020-01-30 12:48 hubert depesz lubaczewski <depesz@depesz.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 4+ messages in thread
From: hubert depesz lubaczewski @ 2020-01-30 12:48 UTC (permalink / raw)
To: memnik@hotmail.com; pgsql-bugs@lists.postgresql.org
On Thu, Jan 30, 2020 at 11:49:45AM +0000, PG Bug reporting form wrote:
> For example this query "
> select to_char('2020-01-29'::date,'Day') " give me this result "Wednesday",
> but this query " select to_char('2020-01-31'::date,'Day') " give me this
> result "Friday ".
> So, i guess it is not right to have days with many spaces as a result and
> some days without any space.
First of all - it's not a bug - function works exactly as documented:
https://www.postgresql.org/docs/current/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABL...
says:
"Day" -> full capitalized day name (blank-padded to 9 chars).
If you don't want the padding, use FM modifier, like:
select to_char('2020-01-31'::date,'FMDay');
Best regards,
depesz
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #16238: Function " to_char(timestamp, text) " doesn't work properly
@ 2020-01-30 16:27 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2020-01-30 16:27 UTC (permalink / raw)
To: memnik@hotmail.com; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> As i noticed the problem is that the function "
> to_char(timestamp, text) " doesn't work properly. For example this query "
> select to_char('2020-01-29'::date,'Day') " give me this result "Wednesday",
> but this query " select to_char('2020-01-31'::date,'Day') " give me this
> result "Friday ".
> So, i guess it is not right to have days with many spaces as a result and
> some days without any space.
No, that's behaving as expected and documented. If you don't want
fixed-width output, use the FM prefix:
=# select to_char('2020-01-31'::date,'-Day-');
to_char
-------------
-Friday -
(1 row)
=# select to_char('2020-01-31'::date,'-FMDay-');
to_char
----------
-Friday-
(1 row)
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #16238: Function " to_char(timestamp, text) " doesn't work properly
@ 2020-01-30 22:57 Nick Memos <memnik@hotmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Nick Memos @ 2020-01-30 22:57 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Ok thanks Tom!
ÁðïêôÞóôå ôï Outlook ãéá Android<https://aka.ms/ghei36;
________________________________
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Thursday, January 30, 2020 6:27:02 PM
To: memnik@hotmail.com <memnik@hotmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16238: Function " to_char(timestamp, text) " doesn't work properly
PG Bug reporting form <noreply@postgresql.org> writes:
> As i noticed the problem is that the function "
> to_char(timestamp, text) " doesn't work properly. For example this query "
> select to_char('2020-01-29'::date,'Day') " give me this result "Wednesday",
> but this query " select to_char('2020-01-31'::date,'Day') " give me this
> result "Friday ".
> So, i guess it is not right to have days with many spaces as a result and
> some days without any space.
No, that's behaving as expected and documented. If you don't want
fixed-width output, use the FM prefix:
=# select to_char('2020-01-31'::date,'-Day-');
to_char
-------------
-Friday -
(1 row)
=# select to_char('2020-01-31'::date,'-FMDay-');
to_char
----------
-Friday-
(1 row)
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-01-30 22:57 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 11:49 BUG #16238: Function " to_char(timestamp, text) " doesn't work properly PG Bug reporting form <noreply@postgresql.org>
2020-01-30 12:48 ` hubert depesz lubaczewski <depesz@depesz.com>
2020-01-30 16:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-01-30 22:57 ` Nick Memos <memnik@hotmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox