Обсуждение: Best practice for specifying an interval

Поиск
Список
Период
Сортировка

Best practice for specifying an interval

От
Mark Morgan Lloyd
Дата:
I notice that section 9.9 of the manual has examples including both HOUR and
HOURS, but the list of reserved words includes only the former.

Am I correct in assuming that

    select time '11:00' - interval '3 hour';

is preferred to

    select time '11:00' - interval '3 hours';


In a similar vein, are fractional hours best specified as

    select time '11:00' - interval '3 hour 45 minute';

or as

    select time '11:00' - interval '3.75 hour';

or with the interval converted to an integer number of minutes?

All these forms appear to work. I've got no intention of jumping ship but am
curious as to the favoured and most portable style.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

Re: Best practice for specifying an interval

От
"Rodrigo De Le�"
Дата:
On 9/24/07, Mark Morgan Lloyd <markMLl.pgsql-general@telemetry.co.uk> wrote:
> In a similar vein, are fractional hours best specified as
>
>         select time '11:00' - interval '3 hour 45 minute';
>
> or as
>
>         select time '11:00' - interval '3.75 hour';
>
> or with the interval converted to an integer number of minutes?

Pg is pretty smart for almost any case.

See:
http://www.postgresql.org/docs/8.2/static/datetime-appendix.html

Re: Best practice for specifying an interval

От
Mark Morgan Lloyd
Дата:
Rodrigo De Le? wrote:

> Pg is pretty smart for almost any case.

Which still doesn't say anything about best practice. In the end I found the
relevant part of the SQL spec, correct forms are HOUR and MINUTE where the
associated numbers are integers.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]