Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: days_in_month() calculates incorrectly #6985

Open
JimRowan opened this issue May 31, 2024 · 0 comments
Open

[Bug]: days_in_month() calculates incorrectly #6985

JimRowan opened this issue May 31, 2024 · 0 comments

Comments

@JimRowan
Copy link

What type of bug is this?

Incorrect result

What subsystems and features are affected?

Other

What happened?

When provided an argument towards the end of the month, days_in_month() gives incorrect results when the following month has a different number of days!

TimescaleDB version affected

2.14.2

PostgreSQL version used

16

What operating system did you use?

RHEL 8.7 x64

What installation method did you use?

RPM

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

No response

How can we reproduce the bug?

# select days_in_month('1/31/2023 00:00:00'::timestamptz);
 days_in_month 
───────────────
            28
(1 row)

Correct value is 31.

# \sf+ days_in_month
        CREATE OR REPLACE FUNCTION public.days_in_month(date timestamp with time zone)
         RETURNS integer
         LANGUAGE sql
         IMMUTABLE PARALLEL SAFE STRICT
         SET search_path TO 'pg_catalog', 'pg_temp'
1       AS $function$
2       SELECT CAST(EXTRACT('day' FROM ($1 + interval '1 month' - $1)) as INTEGER)
3       $function$

Line 2 should be:
SELECT CAST(EXTRACT('day' FROM (date_trunc('month', $1) + interval '1 month' - date_trunc('month', $1))) AS INTEGER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants