From c01289cae5d29f3c3c4e3aa5fcfa911f8bc03c5f Mon Sep 17 00:00:00 2001 From: Nick Griffey Date: Thu, 1 Feb 2024 21:32:09 -0600 Subject: [PATCH] add constraints --- sql/people.sql | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/sql/people.sql b/sql/people.sql index ea7a928..32489d0 100644 --- a/sql/people.sql +++ b/sql/people.sql @@ -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'); update people -set bbrefID = null -where bbrefID = ''; +set + 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 -set retroID = null -where retroID = ''; +set throws = 'B' +where throws = 'S'; CREATE TABLE main."people" ( "ID" text, "birthYear" NUMERIC, - "birthMonth" NUMERIC, - "birthDay" NUMERIC, + "birthMonth" NUMERIC check ("birthMonth" in (1,2,3,4,5,6,7,8,9,10,11,12)), + "birthDay" NUMERIC check ("birthDay" between 1 and 31), "birthCountry" text, "birthState" text, "birthCity" text, - "deathYear" text, - "deathMonth" text, - "deathDay" text, + "deathYear" numeric, + "deathMonth" numeric check ("deathMonth" in (1,2,3,4,5,6,7,8,9,10,11,12)), + "deathDay" numeric check ("deathDay" between 1 and 31), "deathCountry" text, "deathState" text, "deathCity" text, "nameFirst" text, "nameLast" text, "nameGiven" text, - "weight" NUMERIC, - "height" NUMERIC, - "bats" text, - "throws" text, - "debut" text, + "weight" NUMERIC check ("weight" > 0), + "height" NUMERIC check ("height" > 0), + "bats" text check ("bats" in ('L','R','B')), + "throws" text check ("throws" in ('L','R','B')), + "debut" text check (unixepoch("debut") <= unixepoch("finalGame")), "finalGame" text, "retroID" text unique, "bbrefID" text unique,