This article provides a total of two methods:
1. Use the Create extension command
create extension "uuid-OSSP"
After the installation extension is successful, you can query by UUID_GENERATE_V4 () or UUID_GENERATE_V1 ()
Select uuid_generate_v4 ()
2. If PostgreSQL is installed by default, it is not with the UUID function, in order to generate a UUID, we can build on the client.
The function definition already exists in PostgreSQL's installation directory, and all we have to do is import it in.
Under the Share/contrib of the installation directory, you can find uuid-ossp.sql and use the command
psql-d pisces-u postgres-f d:/service/postgresql/9.0/share/contrib/uuid-ossp.sql
Parameter description:
-D: Database name
-U: User name
-F: File to import
If the screen is displayed so that it is correct
You can then execute the query statement in Method 1.
Select uuid_generate_v4 ();
For more information about UUID, you can refer to the official documentation of PostgreSQL.
Use of UUID in PostgreSQL