Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

5.2. Types

5.2.1. Enumerated Types

CREATE TYPE gender AS ENUM ('Male', 'Female');
			
CREATE TABLE person (
    name character varying,
    gender gender
);
			

5.2.2. uuid

create extension "uuid-ossp";
create table products (
	product_id  uuid primary key default uuid_generate_v4()
);
			
-bash-4.1$ psql test
psql (9.2.4)
Type "help" for help.

test=# create extension "uuid-ossp";
CREATE EXTENSION
test=# select uuid_generate_v4();
           uuid_generate_v4
--------------------------------------
 fed01361-b3bd-4844-8a99-34b0d7eab78d
(1 row)

test=# create table products (product_id  uuid primary key default uuid_generate_v4());
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "products_pkey" for table "products"
CREATE TABLE
test=#
test=# insert into products values (default), (default);
INSERT 0 2
test=# select * from products;
              product_id
--------------------------------------
 25bef8e4-35a2-439c-83ed-dd40a61aef92
 ea02a9a3-114d-417f-9a65-7292715538da
(2 rows)

test=#