pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
About the function current_user
9+ messages / 5 participants
[nested] [flat]

* About the function current_user
@ 2023-03-20 07:01 Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Xiong He @ 2023-03-20 07:01 UTC (permalink / raw)
  To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

Dear All,


Just confused,&nbsp; why :
postgres=# select current_user;
&nbsp;current_user
--------------
&nbsp;postgres
(1 row)


postgres=# select current_user();
2023-03-20 07:00:02.981 UTC [17281] ERROR:&nbsp; syntax error at or near "(" at character 20
2023-03-20 07:00:02.981 UTC [17281] STATEMENT:&nbsp; select current_user();
ERROR:&nbsp; syntax error at or near "("
LINE 1: select current_user();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^



why current_user() is not recognized?&nbsp;&nbsp;
But the similar function current_database and current_database(), both can work.



Regards,
Xiong He [iihero]&nbsp;





&nbsp;

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
@ 2023-03-20 07:05 ` Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 9+ messages in thread

From: Pavel Stehule @ 2023-03-20 07:05 UTC (permalink / raw)
  To: Xiong He <iihero@qq.com>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

Hi


po 20. 3. 2023 v 8:01 odesílatel Xiong He <iihero@qq.com> napsal:

> Dear All,
>
> Just confused,  why :
> postgres=# select current_user;
>  current_user
> --------------
>  postgres
> (1 row)
>
> postgres=# select current_user();
> 2023-03-20 07:00:02.981 UTC [17281] ERROR:  syntax error at or near "(" at
> character 20
> 2023-03-20 07:00:02.981 UTC [17281] STATEMENT:  select current_user();
> ERROR:  syntax error at or near "("
> LINE 1: select current_user();
>                            ^
>
> why current_user() is not recognized?
>

this is not real function - it is pseudo constant

The real function in postgres has a record in the pg_proc table.

Regards

Pavel



> But the similar function current_database and current_database(), both can
> work.
>
> Regards,
> Xiong He [iihero]
>
>
>
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
@ 2023-03-20 08:16   ` Daniel Gustafsson <daniel@yesql.se>
  2023-03-20 08:49     ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
  2023-03-20 08:56     ` Re: About the function current_user Xiong He <iihero@qq.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Daniel Gustafsson @ 2023-03-20 08:16 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Xiong He <iihero@qq.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

> On 20 Mar 2023, at 08:05, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> po 20. 3. 2023 v 8:01 odesílatel Xiong He <iihero@qq.com <mailto:iihero@qq.com>> napsal:

> why current_user() is not recognized?  
> 
> this is not real function - it is pseudo constant
> 
> The real function in postgres has a record in the pg_proc table.

The syntax of current_user and current_role are mandated by the SQL
specification, we have this note in the documentation:

	"current_catalog, current_role, 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."

Given that current_schema and other current_xx functions accept parenthesis
it's easy to understand the confusion though.

--
Daniel Gustafsson






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
@ 2023-03-20 08:49     ` John Naylor <john.naylor@enterprisedb.com>
  2023-03-20 09:35       ` Re: About the function current_user Xiong He <iihero@qq.com>
  1 sibling, 1 reply; 9+ messages in thread

From: John Naylor @ 2023-03-20 08:49 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; Xiong He <iihero@qq.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

On Mon, Mar 20, 2023 at 3:16 PM Daniel Gustafsson <daniel@yesql.se> wrote:

> The syntax of current_user and current_role are mandated by the SQL
> specification, we have this note in the documentation:
>
>         "current_catalog, current_role, 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."

To further illuminate why the last one is special: It's not a
fully-reserved keyword:

$ grep current_ src/include/parser/kwlist.h
PG_KEYWORD("current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_date", CURRENT_DATE, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_role", CURRENT_ROLE, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD,
BARE_LABEL)
PG_KEYWORD("current_time", CURRENT_TIME, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD,
BARE_LABEL)
PG_KEYWORD("current_user", CURRENT_USER, RESERVED_KEYWORD, BARE_LABEL)

--
John Naylor
EDB: http://www.enterprisedb.com

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
  2023-03-20 08:49     ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
@ 2023-03-20 09:35       ` Xiong He <iihero@qq.com>
  2023-03-20 12:13         ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Xiong He @ 2023-03-20 09:35 UTC (permalink / raw)
  To: John Naylor <john.naylor@enterprisedb.com>; Daniel Gustafsson <daniel@yesql.se>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

Great. So if it's in the PG_KEYWORD list,  we should not use current_*()?  


------------------ Original ------------------
From:                                                                                                                        "John Naylor"                                                                                    <john.naylor@enterprisedb.com>;
Date: Mon, Mar 20, 2023 04:49 PM
To: "Daniel Gustafsson"<daniel@yesql.se>;
Cc: "Pavel Stehule"<pavel.stehule@gmail.com>;"Xiong He"<iihero@qq.com>;"pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;
Subject: Re: About the function current_user




On Mon, Mar 20, 2023 at 3:16 PM Daniel Gustafsson <daniel@yesql.se> wrote:

> The syntax of current_user and current_role are mandated by the SQL
> specification, we have this note in the documentation:
>
>         "current_catalog, current_role, 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."

To further illuminate why the last one is special: It's not a fully-reserved keyword:

$ grep current_ src/include/parser/kwlist.h 
PG_KEYWORD("current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_date", CURRENT_DATE, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_role", CURRENT_ROLE, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_time", CURRENT_TIME, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD, BARE_LABEL)
PG_KEYWORD("current_user", CURRENT_USER, RESERVED_KEYWORD, BARE_LABEL)

--
John Naylor
EDB: http://www.enterprisedb.com

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
  2023-03-20 08:49     ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
  2023-03-20 09:35       ` Re: About the function current_user Xiong He <iihero@qq.com>
@ 2023-03-20 12:13         ` John Naylor <john.naylor@enterprisedb.com>
  2023-03-20 13:58           ` Re: About the function current_user Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 1 reply; 9+ messages in thread

From: John Naylor @ 2023-03-20 12:13 UTC (permalink / raw)
  To: Xiong He <iihero@qq.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

On Mon, Mar 20, 2023 at 4:35 PM Xiong He <iihero@qq.com> wrote:
>
> Great. So if it's in the PG_KEYWORD list,  we should not use current_*()?


That was just an explanation, regarding "reserved keywords", since you
asked "why".

The documentation should have the correct uses. If it does, there is no bug
here.

Speaking of bugs, I was wondering why appendix C didn't show up when
searching within the doc website -- it's because the heading in appendix C
spells it "key words", a spelling which seems non-standard and gets
interpreted as "keywords" in a web search.

--
John Naylor
EDB: http://www.enterprisedb.com

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
  2023-03-20 08:49     ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
  2023-03-20 09:35       ` Re: About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 12:13         ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
@ 2023-03-20 13:58           ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Peter Eisentraut @ 2023-03-20 13:58 UTC (permalink / raw)
  To: John Naylor <john.naylor@enterprisedb.com>; Xiong He <iihero@qq.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

On 20.03.23 13:13, John Naylor wrote:
> Speaking of bugs, I was wondering why appendix C didn't show up when 
> searching within the doc website -- it's because the heading in appendix 
> C spells it "key words", a spelling which seems non-standard and gets 
> interpreted as "keywords" in a web search.

The reason for that is that the SQL standard uses mainly "key word". 
But it's also somewhat inconsistent about that.





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
@ 2023-03-20 08:56     ` Xiong He <iihero@qq.com>
  2023-03-20 12:16       ` Re: About the function current_user John Naylor <john.naylor@enterprisedb.com>
  1 sibling, 1 reply; 9+ messages in thread

From: Xiong He @ 2023-03-20 08:56 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

Thanks a lot. 
And how to understand below result? 


postgres=# select current_database();
 current_database
------------------
 postgres
(1 row)


postgres=# select current_database;
ERROR:  column "current_database" does not exist
LINE 1: select current_database;





------------------ Original ------------------
From:                                                                                                                        "Daniel Gustafsson"                                                                                    <daniel@yesql.se>;
Date: Mon, Mar 20, 2023 04:16 PM
To: "Pavel Stehule"<pavel.stehule@gmail.com>;
Cc: "Xiong He"<iihero@qq.com>;"pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;
Subject: Re: About the function current_user



> On 20 Mar 2023, at 08:05, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> po 20. 3. 2023 v 8:01 odesílatel Xiong He <iihero@qq.com <mailto:iihero@qq.com>> napsal:

> why current_user() is not recognized?  
> 
> this is not real function - it is pseudo constant
> 
> The real function in postgres has a record in the pg_proc table.

The syntax of current_user and current_role are mandated by the SQL
specification, we have this note in the documentation:

	"current_catalog, current_role, 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."

Given that current_schema and other current_xx functions accept parenthesis
it's easy to understand the confusion though.

--
Daniel Gustafsson

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: About the function current_user
  2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
  2023-03-20 07:05 ` Re: About the function current_user Pavel Stehule <pavel.stehule@gmail.com>
  2023-03-20 08:16   ` Re: About the function current_user Daniel Gustafsson <daniel@yesql.se>
  2023-03-20 08:56     ` Re: About the function current_user Xiong He <iihero@qq.com>
@ 2023-03-20 12:16       ` John Naylor <john.naylor@enterprisedb.com>
  0 siblings, 0 replies; 9+ messages in thread

From: John Naylor @ 2023-03-20 12:16 UTC (permalink / raw)
  To: Xiong He <iihero@qq.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>

On Mon, Mar 20, 2023 at 3:57 PM Xiong He <iihero@qq.com> wrote:
>
> Thanks a lot.
> And how to understand below result?
>
> postgres=# select current_database();
>  current_database
> ------------------
>  postgres
> (1 row)
>
> postgres=# select current_database;
> ERROR:  column "current_database" does not exist
> LINE 1: select current_database;

"current_database" is not a keyword.

--
John Naylor
EDB: http://www.enterprisedb.com

^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2023-03-20 13:58 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 07:01 About the function current_user Xiong He <iihero@qq.com>
2023-03-20 07:05 ` Pavel Stehule <pavel.stehule@gmail.com>
2023-03-20 08:16   ` Daniel Gustafsson <daniel@yesql.se>
2023-03-20 08:49     ` John Naylor <john.naylor@enterprisedb.com>
2023-03-20 09:35       ` Xiong He <iihero@qq.com>
2023-03-20 12:13         ` John Naylor <john.naylor@enterprisedb.com>
2023-03-20 13:58           ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
2023-03-20 08:56     ` Xiong He <iihero@qq.com>
2023-03-20 12:16       ` John Naylor <john.naylor@enterprisedb.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox