在上:
=> SHOW rds.extensions;
rds.extensions
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
btree_gin,btree_gist,chkpass,citext,cube,dblink,dict_int,dict_xsyn,earthdistance,fuzzystrmatch,hstore,intagg,intarray,isn,ltree,pgcrypto,pgrowlocks,pg_trgm,plperl,plpgsql,pltcl,postgis,postgis_tiger_geocoder,postgis_topology,sslinfo,tablefunc,tsearch2,unaccent,uuid-ossp
(1 row)如您所见,uuid-ossp扩展确实存在。但是,当我调用函数以生成uuid_v4时,它会失败:
CREATE TABLE my_table (
id uuid DEFAULT uuid_generate_v4() NOT NULL,
name character varying(32) NOT NULL,
);这是怎么回事?
发布于 2014-03-17 03:38:49
这个扩展是可用的,但没有安装在这个数据库中。
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";发布于 2016-10-12 20:22:02
如果扩展已经存在,但是在执行uuid_generate_v4函数\df命令时没有看到它,那么只需删除扩展并重新添加它,以便函数也被添加。以下是复制问题:
db=# \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+---------------------+------
(0 rows)
CREATE EXTENSION "uuid-ossp";
ERROR: extension "uuid-ossp" already exists
DROP EXTENSION "uuid-ossp";
CREATE EXTENSION "uuid-ossp";
db=# \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+--------------------+------------------+---------------------------+--------
public | uuid_generate_v1 | uuid | | normal
public | uuid_generate_v1mc | uuid | | normal
public | uuid_generate_v3 | uuid | namespace uuid, name text | normal
public | uuid_generate_v4 | uuid | | normal
db=# select uuid_generate_v4();
uuid_generate_v4
--------------------------------------
b19d597c-8f54-41ba-ba73-02299c1adf92
(1 row)可能发生的情况是,扩展最初是在过去的某个时候添加到集群中的,之后您可能在集群中创建了一个新的数据库。如果是这样的话,那么新的数据库只会“知道”扩展,但是它不会添加uuid函数,这是在添加扩展时发生的。因此,您必须重新添加它。
发布于 2017-01-29 14:04:47
看起来,扩展没有安装在您需要的特定数据库中。
您应该连接到这个特定的数据库。
\CONNECT my_database然后在这个数据库中安装扩展
CREATE EXTENSION "uuid-ossp";https://stackoverflow.com/questions/22446478
复制相似问题