+ 接近元素值 postgresql

+ 接近元素值 postgresql

当我试图解决一个问题时(询问于堆栈溢出),当我想查看枚举中存储了哪些数据时,我就会碰到这种类型的结果:

 Schema |    Name     | Internal name | Size |    Elements    | Owner | Access privileges | Description 
--------+-------------+---------------+------+----------------+-------+-------------------+-------------
 public | rights_enum | rights_enum   | 4    | Administrateur+| cvt   |                   | 
        |             |               |      | Utilisateur    |       |                   | 

我的枚举类型在哪里rights_enum。如您所见,此 Enum 中有 2 个值:

  • Administrateur
  • Utilisateur

+元素值旁边 ( 旁边)是什么意思Administrateur?我不认为它只是用于显示的东西。

编辑:这是我的用户表(由于开发,几乎是空的):

 id |        email        |     phone      |                           hashpass                           |  nom   | prenom |   rights    
----+---------------------+----------------+--------------------------------------------------------------+--------+--------+-------------
  1 | [email protected] | 06 54 32 12 34 | $2y$10$5HMULhzKrWSEfCeGklyCueVVwySPFKMqrxw/EqF7V0q3FM99Ejvnu | michel | jean   | Utilisateur

答案1

元素值旁边 (Administrateur 旁边) 的 + 是什么意思?我不认为它只是用来展示的东西。

简短的回答:是的。+字段右侧的代表换行符。

长答案:显示的结果来自\dT+psql,以枚举类型作为参数。

例如:

=> create type mytype as enum('one','two','three');
=> \dT+ mytype
                                      List of data types
 Schema |  Name  | Internal name | Size | Elements | Owner  | Access privileges | Description 
--------+--------+---------------+------+----------+--------+-------------------+-------------
 public | mytype | mytype        | 4    | one     +| daniel |                   | 
        |        |               |      | two     +|        |                   | 
        |        |               |      | three    |        |                   | 

此命令发送一个查询,您可以通过以下设置查看:\set ECHO_HIDDEN on

=> \set ECHO_HIDDEN on
=> \dT+ mytype
********* QUERY **********
SELECT n.nspname as "Schema",
  pg_catalog.format_type(t.oid, NULL) AS "Name",
  t.typname AS "Internal name",
  CASE WHEN t.typrelid != 0
      THEN CAST('tuple' AS pg_catalog.text)
    WHEN t.typlen < 0
      THEN CAST('var' AS pg_catalog.text)
    ELSE CAST(t.typlen AS pg_catalog.text)
  END AS "Size",
  pg_catalog.array_to_string(
      ARRAY(
          SELECT e.enumlabel
          FROM pg_catalog.pg_enum e
          WHERE e.enumtypid = t.oid
          ORDER BY e.enumsortorder
      ),
      E'\n'
  ) AS "Elements",
  pg_catalog.pg_get_userbyid(t.typowner) AS "Owner",
pg_catalog.array_to_string(t.typacl, E'\n') AS "Access privileges",
    pg_catalog.obj_description(t.oid, 'pg_type') as "Description"
FROM pg_catalog.pg_type t
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid))
  AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
  AND (t.typname OPERATOR(pg_catalog.~) '^(mytype)$'
        OR pg_catalog.format_type(t.oid, NULL) OPERATOR(pg_catalog.~) '^(mytype)$')
  AND pg_catalog.pg_type_is_visible(t.oid)
ORDER BY 1, 2;

然后,您可以找到这些换行符的来源:它们来自pg_catalog.array_to_string()作为数组传递的枚举标签和E'\n'分隔符(又名换行符)。

答案2

表中的管理员以 标记,+表明当前访问数据库的人是数据库的管理员,而不是非管理员用户。

相关内容