Thread: [GENERAL] Create database from template and include comment

[GENERAL] Create database from template and include comment

From
Peter Devoy
Date:
Hi all

If when creating a database I use another user-defined database as a template I would like the option for the comment on the template database to also exist for the new database.  Am I correct in thinking there is no feature for this, perhaps because the global nature of pg_shdescription?

For an example of the default behavior:

CREATE DATABASE test_comment_template;
COMMENT ON DATABASE test_comment_template IS 'hello world';

CREATE DATABASE test_comment WITH TEMPLATE test_comment_template;

SELECT oid, datname, shobj_description(oid, 'pg_database')
FROM   pg_database
WHERE  datname LIKE 'test_comment%';

  oid   |        datname        | shobj_description
--------+-----------------------+-------------------
 828611 | test_comment_template | hello world
 828612 | test_comment          |


DROP DATABASE test_comment;
DROP DATABASE test_comment_template;

Kind regards


Peter