forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
26 lines (23 loc) · 886 Bytes
/
init.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CREATE UNLOGGED TABLE "clientes" (
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"limite" INTEGER NOT NULL,
"saldo" INTEGER NOT NULL
);
alter table clientes add constraint saldo check (
saldo > 0
or abs(saldo) <= limite
);
INSERT INTO clientes VALUES (1, 100000, 0);
INSERT INTO clientes VALUES (2, 80000, 0);
INSERT INTO clientes VALUES (3, 1000000, 0);
INSERT INTO clientes VALUES (4, 10000000, 0);
INSERT INTO clientes VALUES (5, 500000, 0);
CREATE UNLOGGED TABLE "transacoes" (
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"valor" INTEGER NOT NULL,
"tipo" CHAR(1) DEFAULT 'd' CHECK (tipo IN ('d', 'c')) NOT NULL,
"descricao" VARCHAR(10) NOT NULL,
"realizada_em" timestamp with time zone NOT NULL DEFAULT (NOW ()),
"cliente_id" INTEGER NOT NULL,
FOREIGN KEY ("cliente_id") REFERENCES "clientes" ("id")
);