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 #836

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

[Bug]: days_in_month() calculates incorrectly #836

JimRowan opened this issue May 31, 2024 · 0 comments
Labels
bug Something isn't working

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)
@JimRowan JimRowan added the bug Something isn't working label May 31, 2024
@antekresic antekresic transferred this issue from timescale/timescaledb Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant