Table 4-25. Session Information Functions
Name | Return Type | Description |
---|---|---|
current_user | name | user name of current execution context |
session_user | name | session user name |
user | name | equivalent to current_user |
The session_user is the user that initiated a database connection; it is fixed for the duration of that connection. The current_user is the user identifier that is applicable for permission checking. Currently it is always equal to the session user, but in the future there might be "setuid" functions and other facilities to allow the current user to change temporarily. In Unix parlance, the session user is the "real user" and the current user is the "effective user".
Note that these functions have special syntactic status in SQL: they must be called without trailing parentheses.
Deprecated: The function getpgusername() is an obsolete equivalent of current_user.
Table 4-26. System Information Functions
Name | Return Type | Description |
---|---|---|
version | text | PostgreSQL version information |
version() returns a string describing the PostgreSQL server's version.
Table 4-27. Access Privilege Inquiry Functions
Name | Return Type | Description |
---|---|---|
has_table_privilege(user, table, access) | boolean | does user have access to table |
has_table_privilege(table, access) | boolean | does current user have access to table |
has_table_privilege determines whether a user can access a table in a particular way. The user can be specified by name or by ID (pg_user.usesysid), or if the argument is omitted current_user is assumed. The table can be specified by name or by OID. (Thus, there are actually six variants of has_table_privilege, which can be distinguished by the number and types of their arguments.) The desired access type is specified by a text string, which must evaluate to one of the values SELECT, INSERT, UPDATE, DELETE, RULE, REFERENCES, or TRIGGER. (Case of the string is not significant, however.)
Table 4-28. Catalog Information Functions
Name | Return Type | Description |
---|---|---|
pg_get_viewdef(viewname) | text | Get CREATE VIEW command for view |
pg_get_ruledef(rulename) | text | Get CREATE RULE command for rule |
pg_get_indexdef(indexOID) | text | Get CREATE INDEX command for index |
pg_get_userbyid(userid) | name | Get user name given sysid |
These functions extract information from the system catalogs. pg_get_viewdef(), pg_get_ruledef(), and pg_get_indexdef() respectively reconstruct the creating command for a view, rule, or index. (Note that this is a decompiled reconstruction, not the verbatim text of the command.) pg_get_userbyid() extracts a user's name given a usesysid value.