最近,我在尝试使用Django的hstore时遇到了麻烦。我是这样安装hstore的:
(参考链接)$ sudo -u postgres psql
postgres=# CREATE EXTENSION hstore;
WARNING: => is deprecated as an operator name
DETAIL: This name may be disallowed altogether in future versions of PostgreSQL.
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+--------------------------------------------------
hstore | 1.0 | public | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
我天真地以为我的新数据库将包括hstore,但事实并非如此:
$ createdb dbtest
$ psql -d dbtest -c '\dx'
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
有没有一种自动在新创建的数据库中使用hstore的方法?
template1
。任何数据库都可以作为模板:CREATE DATABASE foo TEMPLATE mytemplate
。或者,一旦您在template1
中添加了其他内容,您可以使用(默认为空的)template0
。 - Erwin Brandstetter