Getting the encoding of a Postgres database

前端 未结 6 453
感情败类
感情败类 2021-01-30 09:57

I have a database, and I need to know the default encoding for the database. I want to get it from the command line.

6条回答
  •  春和景丽
    2021-01-30 10:33

    tl;dr

    SELECT character_set_name 
    FROM information_schema.character_sets 
    ;
    

    Standard way: information_schema

    From the SQL-standard schema information_schema present in every database/catalog, use the defined view named character_sets. This approach should be portable across all standard database systems.

    SELECT * 
    FROM information_schema.character_sets 
    ;
    

    Despite the name being plural, it shows only a single row, reporting on the current database/catalog.

    The third column is character_set_name:

    Name of the character set, currently implemented as showing the name of the database encoding

提交回复
热议问题