Skip to content

Commit 06f1b48

Browse files
committed
initial commit
0 parents  commit 06f1b48

34 files changed

+1472
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# java-cli-sbt-postgres-data-type-user-defined
2+
3+
## Description
4+
Creates a small database table
5+
called `dog`. This table, `dog`, has been normalized to 3NF.
6+
Two new tables have been added, `breedLookup` and `colorLookup`.
7+
8+
Creates a new table `dog_expanded` that joins
9+
`dog`, `breedLookup` and `colorLookup`. Added clustered indexes on
10+
`dog`.breedId and `dog`.colorId.
11+
12+
Turned `dog_expanded` into a view with an implicit index on `dog_expanded`.id.
13+
14+
Defined a type `type_int_int` that acts as a return type.
15+
Using table function with the aggregate function
16+
COUNT, create a new view `breed_count`.
17+
18+
All output normally
19+
seen in a terminal will be in `java-srv/log` which will dump to the screen. The project may seem to hang but the logs from the container must be written to the project this can take up to 3 min.
20+
21+
## Tech stack
22+
- java
23+
- sbt
24+
- log4j
25+
- postgres driver
26+
27+
## Docker stack
28+
- hseeberger/scala-sbt:11.0.2-oraclelinux7_1.3.5_2.12.10
29+
- postgres
30+
31+
## To run
32+
`sudo ./install.sh -u`
33+
Creates java-srv/log
34+
35+
## To stop
36+
`sudo ./install.sh -d`
37+
Removes java-srv/log
38+
39+
## For help
40+
`sudo ./install.sh -h`
41+
42+
## Credit
43+
- [Pretty sql print](https://github.com/htorun/dbtableprinter)
44+
- [User defined type](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-user-defined-data-types/)

db/data_dump.tar.gz

45 Bytes
Binary file not shown.

db/sql/00-create-table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE SEQUENCE dog_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."dog" (
4+
"id" integer DEFAULT nextval('dog_id_seq') NOT NULL,
5+
"breedId" integer NOT NULL,
6+
"colorId" integer NOT NULL
7+
) WITH (oids = false);

db/sql/01-table-insert.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO "animal"."public"."dog" ("breedId", "colorId")
2+
VALUES
3+
(1, 1),
4+
(1, 2),
5+
(1, 3),
6+
(2, 2),
7+
(3, 2),
8+
(3, 3),
9+
(4, 3),
10+
(4, 4);

db/sql/02-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE breedLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."breedLookup" (
4+
"id" integer DEFAULT nextval('breedLookup_id_seq') NOT NULL,
5+
"breed" text NOT NULL
6+
) WITH (oids = false);

db/sql/03-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."breedLookup" (breed)
2+
VALUES
3+
('Am Bulldog'),
4+
('Blue Tick'),
5+
('Labrador'),
6+
('Gr Shepard');

db/sql/04-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE colorLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."colorLookup" (
4+
"id" integer DEFAULT nextval('colorLookup_id_seq') NOT NULL,
5+
"color" text NOT NULL
6+
) WITH (oids = false);

db/sql/05-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."colorLookup" (color)
2+
VALUES
3+
('White'),
4+
('Grey'),
5+
('Black'),
6+
('Brown');

db/sql/06-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE "public"."dog_expanded" AS (
2+
SELECT a.id, b.breed, c.color
3+
FROM dog AS a
4+
JOIN "breedLookup" AS b ON b.id = a."breedId"
5+
JOIN "colorLookup" AS c ON c.id = a."colorId"
6+
);

db/sql/07-create-index.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE INDEX "IDX_breed" on dog("breedId");
2+
CREATE INDEX "IDX_color" on dog("colorId");

0 commit comments

Comments
 (0)