add constraints

This commit is contained in:
Nick Griffey 2024-02-01 21:32:09 -06:00
parent 0f99098de5
commit c01289cae5
1 changed files with 27 additions and 14 deletions

View File

@ -13,35 +13,48 @@ insert into people values
('thompan01', null, null, null, null, null, null, null, null, null, null, null, null, null, 'Thompson', null, null, null, null, null, '1875-04-26', '1875-05-17', null, 'thompan01'); ('thompan01', null, null, null, null, null, null, null, null, null, null, null, null, null, 'Thompson', null, null, null, null, null, '1875-04-26', '1875-05-17', null, 'thompan01');
update people update people
set bbrefID = null set
where bbrefID = ''; birthYear = nullif(birthYear, ''),
birthMonth = nullif(birthMonth, ''),
birthDay = nullif(birthDay, ''),
deathYear = nullif(deathYear, ''),
deathMonth = nullif(deathMonth, ''),
deathDay = nullif(deathDay, ''),
weight = nullif(weight, ''),
height = nullif(height, ''),
bats = nullif(bats, ''),
throws = nullif(throws, ''),
debut = nullif(debut, ''),
finalGame = nullif(finalGame, ''),
bbrefID = nullif(bbrefid, ''),
retroID = nullif(retroid, '');
update people update people
set retroID = null set throws = 'B'
where retroID = ''; where throws = 'S';
CREATE TABLE main."people" ( CREATE TABLE main."people" (
"ID" text, "ID" text,
"birthYear" NUMERIC, "birthYear" NUMERIC,
"birthMonth" NUMERIC, "birthMonth" NUMERIC check ("birthMonth" in (1,2,3,4,5,6,7,8,9,10,11,12)),
"birthDay" NUMERIC, "birthDay" NUMERIC check ("birthDay" between 1 and 31),
"birthCountry" text, "birthCountry" text,
"birthState" text, "birthState" text,
"birthCity" text, "birthCity" text,
"deathYear" text, "deathYear" numeric,
"deathMonth" text, "deathMonth" numeric check ("deathMonth" in (1,2,3,4,5,6,7,8,9,10,11,12)),
"deathDay" text, "deathDay" numeric check ("deathDay" between 1 and 31),
"deathCountry" text, "deathCountry" text,
"deathState" text, "deathState" text,
"deathCity" text, "deathCity" text,
"nameFirst" text, "nameFirst" text,
"nameLast" text, "nameLast" text,
"nameGiven" text, "nameGiven" text,
"weight" NUMERIC, "weight" NUMERIC check ("weight" > 0),
"height" NUMERIC, "height" NUMERIC check ("height" > 0),
"bats" text, "bats" text check ("bats" in ('L','R','B')),
"throws" text, "throws" text check ("throws" in ('L','R','B')),
"debut" text, "debut" text check (unixepoch("debut") <= unixepoch("finalGame")),
"finalGame" text, "finalGame" text,
"retroID" text unique, "retroID" text unique,
"bbrefID" text unique, "bbrefID" text unique,