fancier way of creating type

This commit is contained in:
Stefan Midjich 2017-03-06 16:35:27 +01:00
parent da34f9017c
commit 622827b4e8
1 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,15 @@
create type inet_protocol as enum ('tcp', 'udp');
-- create type inet_protocol as enum ('tcp', 'udp');
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'inet_protocol') THEN
CREATE TYPE inet_protocol AS enum ('tcp', 'udp');
END IF;
--more types here...
END$$;
create table if not exists client (
client_id uuid NOT NULL primary key unique,
client_id uuid NOT NULL unique,
created timestamp NOT NULL,
ip_address inet NOT NULL,
protocol inet_protocol NOT NULL,