Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: add pg_encoding_to_char() #26380

Closed
BramGruneir opened this issue Jun 4, 2018 · 1 comment
Closed

sql: add pg_encoding_to_char() #26380

BramGruneir opened this issue Jun 4, 2018 · 1 comment
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@BramGruneir
Copy link
Member

BramGruneir commented Jun 4, 2018

pg_encoding_to_char() translates the value in the pg_database.encoding column into a string that represents the encoding. See https://www.postgresql.org/docs/10/static/catalog-pg-database.html

Since CockroachDB uses UTF-8 everywhere this should be straightforward, but the function should assert that its argument is the value presented in pg_database.encoding.

PGAdmin issues the following query:

SELECT db.oid AS did,
       db.datname AS name,
       db.dattablespace AS spcoid,
       spcname,
       datallowconn,
       pg_encoding_to_char(encoding) AS encoding,
       pg_get_userbyid(datdba) AS datowner,
       datcollate,
       datctype,
       datconnlimit,
       has_database_privilege(db.oid, 'CREATE') AS cancreate,
       current_setting('default_tablespace') AS default_tablespace,
       descr.description AS comments,
       db.datistemplate AS is_template,
       (
         SELECT array_to_string(ARRAY (
          SELECT array_to_string(defaclacl::TEXT[], ', ')
          FROM pg_default_acl
          WHERE (defaclobjtype = 'r')
            AND (defaclnamespace = 0::OID)
         ), ', ')
        ) AS tblacl,
        (
          SELECT array_to_string(ARRAY (
            SELECT array_to_string(defaclacl::TEXT[], ', ')
            FROM pg_default_acl
            WHERE (defaclobjtype = 'S')
              AND (defaclnamespace = 0::OID)
          ), ', ')
        ) AS seqacl,
        (
          SELECT array_to_string(ARRAY (
            SELECT array_to_string(defaclacl::TEXT[], ', ')
            FROM pg_default_acl
            WHERE (defaclobjtype = 'f')
              AND (defaclnamespace = 0::OID)
          ), ', ')
        ) AS funcacl,
        (
          SELECT array_to_string(ARRAY (
            SELECT array_to_string(defaclacl::TEXT[], ', ')
            FROM pg_default_acl
            WHERE (defaclobjtype = 'T')
              AND (defaclnamespace = 0::OID)
          ), ', ')
        ) AS typeacl,
        (
          SELECT array_agg((provider || '=') || label)
          FROM pg_shseclabel AS sl1
          WHERE sl1.objoid = db.oid
        ) AS seclabels,
        array_to_string(datacl::TEXT[], ', ') AS acl
FROM pg_database AS db
LEFT JOIN pg_tablespace AS ta
  ON db.dattablespace = ta.oid
LEFT JOIN pg_shdescription AS descr
  ON ((db.oid = descr.objoid) AND (descr.classoid = 'pg_database'::REGCLASS))
WHERE db.oid > NULL::OID
ORDER BY datname

Details can be found here: https://www.postgresql.org/docs/current/static/libpq-control.html

@BramGruneir BramGruneir added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Jun 4, 2018
@BramGruneir BramGruneir added this to the 2.1 milestone Jun 4, 2018
@BramGruneir BramGruneir self-assigned this Jun 4, 2018
@knz knz mentioned this issue Jun 4, 2018
25 tasks
@knz knz added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jun 5, 2018
@knz knz modified the milestones: 2.1, 2.2 Aug 30, 2018
@petermattis petermattis removed this from the 2.2 milestone Oct 5, 2018
@jordanlewis
Copy link
Member

This was added a while back, and the pasted query works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

No branches or pull requests

4 participants