Обсуждение: now() vs current_user

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

now() vs current_user

От
"Ottó Havasvölgyi"
Дата:
Hi,

What is the cause that "now()" works but "now" does not and
"current_user" works but "current_user()" does not. They are both
functions, and are present in pg_proc. How can I decide if a function
needs parentheses or not if it has no parameters?

Thanks in advance,
Otto

Re: now() vs current_user

От
Michael Glaesemann
Дата:
On Sep 5, 2007, at 15:31 , Ottó Havasvölgyi wrote:

> What is the cause that "now()" works but "now" does not and

now() is a PostgreSQL extension and not required by the SQL spec. For
the most part, PostgreSQL extensions are functions and look like
them. CURRENT_TIMESTAMP and CURRENT_DATE are required by the SQL spec
and return the appropriate values. IIRC, they call now() with casts,
if appropriate.

> "current_user" works

IIRC, CURRENT_USER (without parens) is required by the SQL spec. It's
most likely implemented in PostgreSQL using the current_user function
and special rules are added to the grammar to allow CURRENT_USER to
be accepted without parens.

> How can I decide if a function
> needs parentheses or not if it has no parameters?

Via the documentation. In general functions require parens. AIUI its
only when they are also SQL keywords that the parens are omitted (as
required by the spec).

Michael Glaesemann
grzm seespotcode net



Re: now() vs current_user

От
"Rodrigo De León"
Дата:
On 9/5/07, Ottó Havasvölgyi <havasvolgyi.otto@gmail.com> wrote:
> What is the cause that "now()" works but "now" does not and
> "current_user" works but "current_user()" does not.

From http://www.postgresql.org/docs/8.2/static/functions-info.html :

"Note:  current_user, session_user, and user have special syntactic
status in SQL: they must be called without trailing parentheses."

See:
http://www.google.com/search?q=sql+current_user