Re: Regarding use case of epoch to generate nanoseconds precision

From: Keith Fiske <keith(dot)fiske(at)crunchydata(dot)com>
To: Durgamahesh Manne <maheshpostgres9(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Regarding use case of epoch to generate nanoseconds precision
Date: 2024-05-22 15:57:40
Message-ID: CAODZiv7ENC3uFkWtncUs8gMxJZYtXVaWO+h4KUjqQ0V-DX2n2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 22, 2024 at 5:21 AM Durgamahesh Manne <maheshpostgres9(at)gmail(dot)com>
wrote:

> Hi
>
> Postgres supports only upto microseconds (6 decimal precision).
> How do we generate timestamp with nanoseconds as rds postgres not
> supported timestamp9 extension ?
> Is there a way to generate timestamp with nanoseconds precision on
> pg_partman with epoch without typecasting or with typecasting ?
>
> p_epoch => (to_timestamp(control column))
> Here what is the control column?
> How to run it with the create_parent function of partman?
>
> Here as per the pg_partman doc
> p_epoch - tells pg_partman that the control column is an integer type, but
> actually represents an epoch time value. Valid values for this option are:
> 'seconds', 'milliseconds', 'nanoseconds', and 'none'. The default is
> 'none'. All table names will be time-based. In addition to a normal index
> on the control column, be sure you create a functional, time-based index on
> the control column (to_timestamp(control column)) as well so this works
> efficiently.
>
>
> Regards,
> Durga Mahesh Manne
>
>
The option in pg_partman simply multiples the normal epoch value by
1000000000 then converts it with to_timestamp().

https://github.com/pgpartman/pg_partman/blob/master/sql/functions/create_partition_time.sql#L119C64-L119C74

I'd already had the millisecond option in partman for epoch, and someone
requested nanosecond precision. It was easy to add the option so I did it
for them, and anyone else that may find it useful. How you actually
implement that level of time precision in an epoch value in your
environment is entirely up to you.

--
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-05-22 16:05:24 Re: Restore of a reference database kills the auto analyze processing.
Previous Message HORDER Philip 2024-05-22 15:55:32 Re: Restore of a reference database kills the auto analyze processing.