Re: Extension development

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Yonatan Misgan <yonamis(at)dtu(dot)edu(dot)et>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Extension development
Date: 2019-08-15 20:53:51
Message-ID: 20190815205351.trwqaybqslhczjri@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Aug 15, 2019 at 06:58:07AM +0000, Yonatan Misgan wrote:
>Hello, I am trying to develop calendar extension for PostgreSQL but
>there is a difficulties on how to get day, month and year from
>PostgreSQL source code because when am read the PostgreSQL source code
>it uses DateADT as a data type and this DateADT returns the total
>numbers of day. So how can I get day, month or year only. For example
>the below code is PostgreSQL source code to return current date.
>/*
>* GetSQLCurrentDate -- implements CURRENT_DATE
>*/
>DateADT
>GetSQLCurrentDate(void)
>{
> TimestampTz ts;
> struct pg_tm tt,
> *tm = &tt;
> fsec_t fsec;
> int tz;
>
> ts = GetCurrentTransactionStartTimestamp();
>
> if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
> ereport(ERROR,
> (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
> errmsg("timestamp out of range")));
>
> return date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
>}
>From this source code how can I get only the year to convert my own
>calendar year. I need this because Ethiopian calendar is totally
>differ from GC in terms of day, month and year.
>

I think you might want to look at timestamptz_part() function, in
timestamp.c. That's what's behind date_part() SQL function, which seems
doing the sort of stuff you need.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2019-08-15 22:30:59 Re: Speed up transaction completion faster after many relations are accessed in a transaction
Previous Message Ibrar Ahmed 2019-08-15 19:21:17 Re: UNION ALL