Re: Is `DATE` a function?

Поиск
Список
Период
Сортировка
От Bzzzz
Тема Re: Is `DATE` a function?
Дата
Msg-id 20231007162823.6c5929c9@msi.defcon1.lan
обсуждение исходный текст
Ответ на Is `DATE` a function?  (jinser <aimer@purejs.icu>)
Список pgsql-novice
On Sat, 7 Oct 2023 21:01:59 +0800
jinser <aimer@purejs.icu> wrote:

Hi,

> Hello, Friends,
>
> Use it like a normal function:
>
> playground=# SELECT DATE();
> ERROR:  function date() does not exist
> LINE 1: SELECT DATE();
>                ^
> HINT:  No function matches the given name and argument types. You
> might need to add explicit type casts.
>
> playground=# SELECT DATE('2022-01-13');
>     date
> ------------
>  2022-01-13
> (1 row)
>
> Another reason I think this is a function is that other types don't
> seem to have the same behavior:
>
> playground=# SELECT integer('123');
> ERROR:  syntax error at or near "("
> LINE 1: SELECT integer('123');
>                       ^
>
> The Table 9.33. Date/Time Functions in the documentation
> (https://www.postgresql.org/docs/16/functions-datetime.html#FUNCTIONS-DATETIME-TABLE)
> doesn't mention this...
> If I missed it, where should I find the description? Or maybe it
> actually should be in this table?

Is is both a function and an operator, but the function has an arity of
one (text, representing a date, timestamp, etc), hence the error message
you've got.
If you just want to get today's date, use : SELECT current_date;
or if you want to twist your mind : SELECT date(now());

Jean-Yves



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

Предыдущее
От: jinser
Дата:
Сообщение: Is `DATE` a function?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Is `DATE` a function?