Re: interval / interval -> double operator

Поиск
Список
Период
Сортировка
От Andrew Hammond
Тема Re: interval / interval -> double operator
Дата
Msg-id 5a0a9d6f0705291647q6cf95bcdpacd3db0a561918f1@mail.gmail.com
обсуждение исходный текст
Ответ на Re: interval / interval -> double operator  ("Andrew Hammond" <andrew.george.hammond@gmail.com>)
Ответы Re: interval / interval -> double operator  (Alvaro Herrera <alvherre@commandprompt.com>)
Список pgsql-hackers
On 5/18/07, Andrew Hammond <andrew.george.hammond@gmail.com> wrote:
On 5/17/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Andrew Hammond" <andrew.george.hammond@gmail.com> writes:
> On 5/17/07, Tom Lane < tgl@sss.pgh.pa.us> wrote:
>> What are the grounds for defining it that way rather than some other
>> way?

> The only alternative that came to mind when I wrote it was using a numeric
> instead of float.

No, I'm wondering what's the justification for smashing it to a single
number at all, when the inputs are three-field values.  Interval divided
by float doesn't produce just a float, for example.


I think I see what you're getting at here. '1 month' / '1 day' could return a number of reasonable values depending on how many days are in the month (28 to 31) and on how many hours are in a day (generally 24, but can be 23 or 25 for DST adjustments). The definition above simply assumes that EXTRACT(epoch...) does the Right Thing. Hmmm. I'm at a loss for the right way to solve this. It seems very reasonable to want to divide intervals by intervals (how many nanocenturies in a fortnight?), but I'm at a loss for how to do that correctly. I'll read the code from EXTRACT(epoch...) and see what happening there.

Ok, I've been hunting through src/backend to try and find the code for EXTRACT(epoch ...). I found EXTRACT in src/backend/parser/gram.y, which seems like a reasonable place to start.

  | EXTRACT '(' extract_list ')'
      {
          FuncCall *n = makeNode(FuncCall);
          n->funcname = SystemFuncName("date_part");
          n->args = $3;
          n->agg_star = FALSE;
          n->agg_distinct = FALSE;
          n->location = @1;
          $$ = (Node *)n;
     }

Which got me looking for "date_part". But that only seems to be in the gram.y file, include/catalog/pg_proc.h and the test suite. The pg_proc.h stuff looks pretty interesting, but to decipher it, I figured I need to read up on SystemFuncName(). So I grepped for SystemFuncName(). It turns out to be a wrapper around list_make2(), which is part of the linked list package. Then I checked out makeNode(), which is a wrapper around newNode(), which in turn is memory allocation stuff. At this point I'm kind of lost. I'm pretty sure that the next thing I need to hunt up is in the parser, but I don't know where to look.

Can anyone please tell me what is the right way to chase down the actual code that implements EXTRACT(epoch ...)? (please note that I'm not asking where that code is, but how to find it.) Or even better, is there a web page or other document someone can give me a pointer to?

Andrew

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Create hooks to let a loadable plugin monitor (or even replace)
Следующее
От: "Jaime Casanova"
Дата:
Сообщение: Re: Reviewing temp_tablespaces GUC patch