PostgreSQL hỗ trợ enum type như thế nào? Có thể thay đổi enum sau khi tạo không?
PostgreSQL hỗ trợ enum type như thế nào? Có thể thay đổi enum sau khi tạo không?
CREATE TYPE order_status AS ENUM ('pending', 'paid', 'shipped');
CREATE TABLE orders (id bigint generated always as identity primary key, status order_status NOT NULL DEFAULT 'pending');
INSERT INTO orders (status) VALUES ('paid');
SELECT * FROM orders WHERE status > 'pending'; -- so sánh theo thứ tự khai báo
SELECT unnest(enum_range(NULL::order_status)); -- liệt kê giá trị
| Thao tác | Hỗ trợ |
|---|---|
| Thêm giá trị | ✔ `ALTER TYPE order_status ADD VALUE 'refunded' [BEFORE |
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.