Re: pg_attribute.atttypmod for interval type

From: Chapman Flack <jcflack(at)acm(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Greg Rychlewski <greg(dot)rychlewski(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_attribute.atttypmod for interval type
Date: 2024-07-28 14:34:53
Message-ID: 66A6570D.2040502@acm.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07/27/24 00:32, Tom Lane wrote:
> Interval typmods include a fractional-seconds-precision field as well
> as a bitmask indicating the allowed interval fields (per the SQL
> standard's weird syntax such as INTERVAL DAY TO SECOND). Looking at
> the source code for intervaltypmodout() might be helpful:
>
> https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/timestamp.c;h=69fe7860ede062fc8be42e7545b35e69c3e068c4;hb=HEAD#l1136

Also, for this kind of question, an overview of a type modifier's
contents can be found in the javadoc for the WIP PL/Java 1.7, which is
intended to model such things accurately.[0]

The model is aimed at the logical level, that is, to represent
what information is present in the typmod, the precise semantics, what
combinations are allowed/disallowed, and so on, but not the way PostgreSQL
physically packs the bits. So, for this case, what you would find there
is essentially what Tom already said, about what's logically present; it
doesn't save you the effort of looking in the PostgreSQL source if you want
to independently implement unpacking the bits.

For possible future typmod questions, it may serve as a quick way to
get that kind of logical-level description at moments when Tom is away
from the keyboard.

Regards,
-Chap

[0]
https://tada.github.io/pljava/preview1.7/pljava-api/apidocs/org.postgresql.pljava/org/postgresql/pljava/adt/Timespan.Interval.Modifier.html

I just noticed a nit in that javadoc: it says the field combination
must be "one of the named constants in this interface" but you don't
find them in the Interval.Modifier interface; they're in the containing
interface Interval itself.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2024-07-28 14:44:46 Re: Vacuum ERRORs out considering freezing dead tuples from before OldestXmin
Previous Message Michael Paquier 2024-07-28 13:20:45 Re: Pluggable cumulative statistics