当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - Postgres: why do some function calls require () and others not?

问题描述:

My question is this:

Why do some postgresql functions require an empty bracket and others don't and how can I tell the correct syntax?

Examples:

This does not work

select pg_postmaster_start_time;

results in

ERROR: column "pg_postmaster_start_time" does not exist

LINE 1: select pg_postmaster_start_time;

^

However this works:

select pg_postmaster_start_time();

resulting in

 pg_postmaster_start_time

-------------------------------

2016-08-01 16:07:12.728306+01

(1 row)

Now for the converse case: This works

select current_user;

and it results in

 current_user

--------------

edbstore

(1 row)

But this does not work

select current_user();

Resulting in

ERROR: syntax error at or near "("

LINE 1: select current_user();

^

I did find this has been asked here, but there didn't seem to be an answer

网友答案:

Read docs - it says

Note: current_catalog, current_schema, current_user, session_user, and user have special syntactic status in SQL: they must be called without trailing parentheses. (In PostgreSQL, parentheses can optionally be used with current_schema, but not with the others.)

I know it sounds like "because it says so", so does not actually answer your question. But this is how docs explain it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: