SHOW USERS¶
列出系统中的所有 用户。
语法¶
SHOW [ TERSE ] USERS
[ LIKE '<pattern>' ]
[ STARTS WITH '<name_string>' ]
[ LIMIT <rows> [ FROM '<name_string>' ] ]
参数¶
TERSE仅返回以下输出列:
namecreated_ondisplay_namefirst_namelast_nameemailorg_identitycommenthas_passwordhas_rsa_public_keytypehas_mfahas_pathas_federated_workload_authentication
LIKE 'pattern'(可选)按对象名称筛选命令输出。筛选器使用 不区分大小写 的模式匹配,并支持 SQL 通配符(
%和_)。例如,以下模式返回 相同的 结果:
... LIKE '%testing%' ...... LIKE '%TESTING%' .... 默认:无值(不对输出应用筛选)。
STARTS WITH 'name_string'(可选)根据对象名称开头显示的字符筛选命令输出。该字符串必须放在单引号内并且 区分大小写。
例如,以下字符串会返回 不同的 结果:
... STARTS WITH 'B' ...... STARTS WITH 'b' .... 默认:无值(不对输出应用筛选)
LIMIT rows [ FROM 'name_string' ](可选)限制返回的最大行数,同时还对结果启用“分页”功能。返回的实际行数可能小于指定的限制。例如,现有对象的数量小于指定的限制。
可选的
FROM 'name_string'分子句实际上会充当结果的“游标”。这样就可以提取对象名称与指定字符串匹配的第一行之后的指定行数:该字符串必须放在单引号内并且 区分大小写。
该字符串不必包含完整的对象名称;支持部分名称。
默认:无值(不对输出应用限制)
备注
对于支持
FROM 'name_string'和STARTS WITH 'name_string'的 SHOW 子句,您可以将这两个子句组合在同一语句中。但是,两个条件都必须满足,否则它们相互抵消,不返回任何结果。此外,对象按名称的字典顺序返回,因此
FROM 'name_string'仅返回字典值高于STARTS WITH 'name_string'所返回行的行。例如:
... STARTS WITH 'A' LIMIT ... FROM 'B'不会返回任何结果。... STARTS WITH 'B' LIMIT ... FROM 'A'不会返回任何结果。... STARTS WITH 'A' LIMIT ... FROM 'AB'将返回结果(如果有任何行与输入字符串匹配)。
输出¶
命令的输出包括以下列,它们描述了对象的属性和元数据:
列 |
描述 |
|---|---|
|
用户的名称。 |
|
创建用户的日期和时间。 |
|
用户在登录系统时输入的名称。 |
|
针对 Snowsight 中的用户显示的名称。 |
|
用户的名字。 |
|
用户的姓氏。 |
|
用户的电子邮件地址。 |
|
在清除用户登录的临时锁定 之前的分钟数。 |
|
用户状态被设置为“已过期”且不再允许用户登录的天数。 |
|
用户评论。 |
|
If TRUE, the user is locked out of Snowflake and cannot log back in. |
|
If TRUE, the user is forced to change their password on next login (including their first/initial login) into the system. |
|
If TRUE, the user is locked by Snowflake. When a user is locked, they are unable to log in until the lock is removed. |
|
登录时默认为用户会话激活的虚拟仓库。 |
|
登录时默认为用户会话激活的命名空间(仅数据库或数据库和架构)。 |
|
登录时默认为用户会话激活的主要角色。 |
|
登录时在用户会话中处于活跃状态的辅助角色设置。 |
|
If TRUE, Duo is enabled for the user, which requires the user to use MFA (multi-factor authentication) when logging in. |
|
授权用于 Duo 的 ID。 |
|
暂时绕过用户 MFA 要求 的分钟数。 |
|
拥有用户的角色。 |
|
用户上次登录 Snowflake 的日期和时间。 |
|
用户的状态设置为 |
|
在清除用户登录的临时锁定之前的分钟数。 |
|
If TRUE, the user has a password. |
|
If TRUE, the user has a public key for key-pair authentication. |
|
用户的类型。有关可能值的列表,请参阅 用户类型。 |
|
If TRUE, the user is enrolled in multi-factor authentication (MFA). |
|
If TRUE, the user has one or more programmatic access tokens. |
|
If TRUE, the user is configured to authenticate with workload identity federation. |
|
If TRUE, the user was imported from a global organization user. |
访问控制要求¶
任何用户都可以执行 SHOW USERS 命令。输出始终在 name 列中包含用户名。
对于其他列,Snowflake 根据授予用户:ref:活跃角色 <label-access_control_overview_active_roles> 的权限筛选输出。如果活跃角色具有以下 任一 权限,则将返回其他列中的值:
权限 |
对象 |
备注 |
|---|---|---|
OWNERSHIP |
用户 |
|
MANAGE GRANTS |
账户 |
否则,其他列包含 NULL。
有关创建具有指定权限集的自定义角色的说明,请参阅 创建自定义角色。
使用说明¶
如果该账户拥有超过 1 万个用户,则可以使用 LIMIT ... FROM ... 参数返回较小用户集。
例如,您可以运行
SHOW USERS LIMIT 10000 FROM my_user以返回从名为my_user的用户开始的后续 1 万个用户。
该命令不需要正在运行的仓库即可执行。
该命令仅返回当前用户的当前角色已获授至少一项访问权限的对象。
MANAGE GRANTS 访问权限隐式允许其持有者查看账户中的每个对象。默认情况下,只有账户管理员(具有 ACCOUNTADMIN 角色的用户)和安全管理员(具有 SECURITYADMIN 角色的用户)才具有 MANAGE GRANTS 权限。
To post-process the output of this command, you can use the pipe operator (
->>) or the RESULT_SCAN function. Both constructs treat the output as a result set that you can query.The output column names for this command are generated in lowercase. If you consume a result set from this command with the pipe operator or the RESULT_SCAN function, use double-quoted identifiers for the column names in the query to ensure that they match the column names in the output that was scanned. For example, if the name of an output column is
type, then specify"type"for the identifier.
示例¶
以下示例列出了该账户中的用户:
SHOW USERS;
+--------------+-------------------------------+---------------+--------------+------------+-----------+------------------------+----------------+----------------+---------+----------+----------------------+----------------+-------------------+-------------------+--------------+-------------------------+---------------+---------------+--------------------+--------------+-------------------------------+-----------------+-------------------+--------------+--------------------+--------+---------+---------+---------------------------------------+
| name | created_on | login_name | display_name | first_name | last_name | email | mins_to_unlock | days_to_expiry | comment | disabled | must_change_password | snowflake_lock | default_warehouse | default_namespace | default_role | default_secondary_roles | ext_authn_duo | ext_authn_uid | mins_to_bypass_mfa | owner | last_success_login | expires_at_time | locked_until_time | has_password | has_rsa_public_key | type | has_mfa | has_pat | has_federated_workload_authentication |
|--------------+-------------------------------+---------------+------------- +------------+-----------+------------------------+----------------+----------------+---------+----------+----------------------+----------------+-------------------+-------------------+--------------+-------------------------+---------------+---------------+--------------------+--------------+-------------------------------+-----------------+-------------------+--------------+--------------------+--------+---------+---------+---------------------------------------|
| MY_USER_NAME | 2020-04-28 12:24:38.722 -0700 | MY_LOGIN_NAME | Jane Smith | Jane | Smith | jane.smith@example.com | NULL | NULL | NULL | false | false | false | MY_WAREHOUSE | MY_DB.MY_SCHEMA | MY_ROLE | [] | false | NULL | NULL | ACCOUNTADMIN | 2025-06-12 15:02:22.783 -0700 | NULL | NULL | true | true | PERSON | true | true | false |
+--------------+-------------------------------+---------------+--------------+------------+-----------+------------------------+----------------+----------------+---------+----------+----------------------+----------------+-------------------+-------------------+--------------+-------------------------+---------------+---------------+--------------------+--------------+-------------------------------+-----------------+-------------------+--------------+--------------------+--------+---------+---------+---------------------------------------+