Postgres uuid_generate_v1() does not exist [How to Solve]

 

1、 Phenomenon:

schema=# select uuid_generate_v1();

ERROR: function uuid_generate_v1() does not exist

Line 1: select uuid_generate_v1();

^

Warning: No function matches the given name and argument types. You might need to add explicit type casts.

Time: 14.543 ms

2、 Reason:

By default, Postgres has no UUID_ generate_ V1 method, you need to install the extension and enable UUID ossp to use this method.

3、 Solution:

1. Install UUID ossp extension dependent environment

You can use compile install or Yum install, because my environment here is postgres10, yum install, so the yum install extension is preferred.

yum install -y postgresql10-contrib

2. Enable UUID ossp extension

postgres=# create extension "uuid-ossp" ;

CREATE EXTENSION

3. Verification

postgres-# \dx

Installed extensions list

Name | Version | Architecture Mode | Description

-----------+------+------------+-------------------------------------------------

plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language

uuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs)

More details

postgres=# \dx+
        Object used to extend "plpgsql"
               Object description                
---------------------------------------
 Function plpgsql_call_handler()
 function plpgsql_inline_handler(internal)
 function plpgsql_validator(oid)
 Language plpgsql
(4 rows of records)

     object for extending "uuid-ossp"
             Object description             
----------------------------------
 Function uuid_generate_v1()
 function uuid_generate_v1mc()
 function uuid_generate_v3(uuid,text)
 function uuid_generate_v4()
 function uuid_generate_v5(uuid,text)
 function uuid_nil()
 function uuid_ns_dns()
 function uuid_ns_oid()
 function uuid_ns_url()
 function uuid_ns_x500()
(10 lines of records)

Execute again

postgres=# select uuid_generate_v1();
           uuid_generate_v1           
--------------------------------------
 9ffd8cc8-db44-11eb-8952-0050568a41b8
(1 line record)


Read More: