forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
34 lines (31 loc) · 770 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
27
28
29
30
31
32
33
34
DROP TABLE IF EXISTS transacoes;
--
DROP TABLE IF EXISTS clientes;
CREATE UNLOGGED TABLE IF NOT EXISTS clientes (
id SERIAL NOT NULL,
limite INTEGER NOT NULL,
saldo INTEGER NOT NULL,
PRIMARY KEY (id)
);
CREATE UNLOGGED TABLE IF NOT EXISTS transacoes (
id SERIAL NOT NULL,
id_clientes BIGINT NOT NULL,
valor INTEGER NOT NULL,
tipo CHAR(1) NOT NULL,
descricao VARCHAR(10),
realizada_em TIMESTAMP NOT NULL,
PRIMARY KEY (id),
CONSTRAINT fk_clientes
FOREIGN KEY(id_clientes)
REFERENCES clientes(id)
);
DO $$
BEGIN
INSERT INTO clientes (id, limite, saldo)
VALUES
(1, 1000 * 100, 0)
,(2, 800 * 100, 0)
,(3, 10000 * 100, 0)
,(4, 100000 * 100, 0)
,(5, 5000 * 100, 0);
END; $$