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

age() function in postgres not working as expected #425

Open
StanBright opened this issue Dec 13, 2022 · 2 comments
Open

age() function in postgres not working as expected #425

StanBright opened this issue Dec 13, 2022 · 2 comments

Comments

@StanBright
Copy link

StanBright commented Dec 13, 2022

Hi,

First, thanks for the amazing gem/engine you've built. It's an indispensable part of all my projects. Kudos!

I'm using the latest version of blazer (2.6.5 as of now), and I'm trying to incorporate the age() function from Postgres https://www.postgresql.org/docs/current/functions-datetime.html in some of my reports.

For example, showing the latest users and when they were created:

SELECT username, age(now() at time zone 'utc', created_at)
FROM users
ORDER BY created_at DESC

However, instead of date-time-in-words (e.g. "4 days 5 hours"), Blazer's UI returns/renders a float representing the age in seconds - an interval in Postgres. At the same, if I execute the same query in the DB console directly, I'm getting the expected string.

I'm wondering, is that behaviour expected is a kind of bug/known-issue?

Thanks,
Stan

@ankane
Copy link
Owner

ankane commented Dec 15, 2022

Hey @StanBright, thanks for reporting. Postgres use intervalstyle to determine how intervals are displayed. It defaults to postgres, which is probably what you're seeing in the DB console.

It looks like Active Record added support for interval type in 6.1, which changes the style to iso_8601 and parses each value into an ActiveSupport::Duration, which shows the number of seconds when to_s is called.

I agree the current output isn't ideal - will try to spend some time on this in the future.

@StanBright
Copy link
Author

Amazing response. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants