Postgresql:带有“\”的用户角色名义上

发布于 2025-01-14 09:47:31 字数 552 浏览 3 评论 0原文

我在创建角色时犯了一个错字。现在我被“\ruser”困住了,我不知道如何正确地放弃这个角色。以任何方式转义反斜杠都不起作用,使用 unicode 格式不起作用(删除角色 U&'%0Dmyuser';)或任何类型的字符串标记(",',`)都不起作用。有什么想法吗?

server=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 \rmyuser  | Superuser, Create role, Create DB                          | {}
 myuser    | Superuser, Create role, Create DB                          | {}

I made a typo while creating a role. Now I'm stuck with "\ruser" and I have no clue how to properly drop that role. Escaping the backslash in any kind of way doesn't work, using unicode formating doesnt work (drop role U&'%0Dmyuser';) or any kind of string markings (",',`) won't work. Any ideas?

server=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 \rmyuser  | Superuser, Create role, Create DB                          | {}
 myuser    | Superuser, Create role, Create DB                          | {}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装纯掩盖桑 2025-01-21 09:47:31

只需用双引号转义标识符:

DROP ROLE "\rmyuser";

如果 \r 不是反斜杠和 r,而是“回车符”的转义版本,最简单的方法可能是使用动态 SQL、扩展字符串文字语法和 format 函数:

DO $BEGIN EXECUTE format('DROP ROLE %I', E'\rmyuser'); END;$;

Simply escape the identifier with double quotes:

DROP ROLE "\rmyuser";

In the case that \r is not a backslash and an r, but an escaped version of "carriage return", the simplest way may be to use dynamic SQL, the extended string literal syntax and the format function:

DO $BEGIN EXECUTE format('DROP ROLE %I', E'\rmyuser'); END;$;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文