Re: Extension development

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема Re: Extension development
Дата
Msg-id 20190815205351.trwqaybqslhczjri@development
обсуждение исходный текст
Ответ на Extension development  (Yonatan Misgan <yonamis@dtu.edu.et>)
Список 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 



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ibrar Ahmed
Дата:
Сообщение: Re: UNION ALL
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: Speed up transaction completion faster after many relations areaccessed in a transaction