Shuffle around some folders, add test_scores.sql
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
This folder includes code and data used in [chapter 4 of PostgreSQL: Up and Running, 4th Edition](https://www.oreilly.com/library/view/postgresql-up-and/9798341660885/ch04.html)
|
||||
This folder includes code used in [chapter 4 of PostgreSQL: Up and Running, 4th Edition](https://www.oreilly.com/library/view/postgresql-up-and/9798341660885/ch04.html)
|
||||
|
||||
* The folder *ACSST1Y2024.S2502_2026-01-02T144528* was exported from link [State Housing Demographics](https://data.census.gov/table?q=S2502:+Demographic+Characteristics+for+Occupied+Housing+Units&g=040XX00US01,02,04,05,06,08,09,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,53,54,55,56,72)
|
||||
29
ch04/import_acs_data.psql
Normal file
29
ch04/import_acs_data.psql
Normal file
@@ -0,0 +1,29 @@
|
||||
\connect postgresql_book
|
||||
\cd /postgresql_up_and_running_4e_code_data/raw/ACSST1Y2024.S2502
|
||||
|
||||
DROP TABLE IF EXISTS staging.lu_acs_columns;
|
||||
CREATE TABLE staging.lu_acs_columns(column_name text, label text);
|
||||
\copy staging.lu_acs_columns FROM ACSST1Y2024.S2502-Column-Metadata.csv CSV HEADER
|
||||
|
||||
DROP TABLE IF EXISTS staging.acs_data_raw;
|
||||
SELECT 'CREATE TABLE staging.acs_data_raw('
|
||||
|| string_agg( quote_ident( lower(column_name) )
|
||||
|| ' text', ',') || ');'
|
||||
FROM staging.lu_acs_columns
|
||||
\gexec
|
||||
ALTER TABLE staging.acs_data_raw ADD COLUMN unknown text;
|
||||
|
||||
\copy staging.acs_data_raw FROM ACSST1Y2024.S2502-Data.csv WITH (format 'csv', HEADER)
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS census;
|
||||
DROP TABLE IF EXISTS census.acs_data;
|
||||
SELECT 'CREATE TABLE census.acs_data AS
|
||||
SELECT '
|
||||
|| string_agg( 'NULLIF(' || quote_ident( lower(column_name) ) || ', ''N'') '
|
||||
|| CASE WHEN column_name IN('GEO_ID', 'NAME') THEN '::text' ELSE '::numeric' END
|
||||
|| ' AS '
|
||||
|| quote_ident( lower(column_name) ) , ',' ) || '
|
||||
FROM staging.acs_data_raw
|
||||
WHERE geo_id <> ''Geography'';'
|
||||
FROM staging.lu_acs_columns
|
||||
\gexec
|
||||
3
raw/README.md
Normal file
3
raw/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
This folder includes code and data used in [chapter 4 of PostgreSQL: Up and Running, 4th Edition](https://www.oreilly.com/library/view/postgresql-up-and/9798341660885/ch04.html)
|
||||
|
||||
* The folder *ACSST1Y2024.S2502_2026-01-02T144528* was exported from link [State Housing Demographics](https://data.census.gov/table?q=S2502:+Demographic+Characteristics+for+Occupied+Housing+Units&g=040XX00US01,02,04,05,06,08,09,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,53,54,55,56,72)
|
||||
61
raw/test_scores.sql
Normal file
61
raw/test_scores.sql
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
CREATE TABLE public.test_scores (
|
||||
student character varying(100) NOT NULL,
|
||||
subject character varying(100) NOT NULL,
|
||||
score numeric(5,0),
|
||||
test_date date NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'algebra', 68, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'physics', 83, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'chemistry', 71, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'calculus', 68, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'scheme', 90, '2015-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'algebra', 84, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'physics', 72, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'chemistry', 71, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'calculus', 69, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'algebra', 74, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'physics', 83, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'chemistry', 80, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'calculus', 70, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'algebra', 75, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'physics', 72, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'chemistry', 82, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'calculus', 65, '2014-01-15');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'algebra', 77, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'physics', 85, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'chemistry', 76, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('regina', 'calculus', 61, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'algebra', 80, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'physics', 72, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'chemistry', 80, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('leo', 'calculus', 62, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'algebra', 74, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'physics', 79, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'chemistry', 84, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('alex', 'calculus', 77, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'algebra', 78, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'physics', 72, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'chemistry', 86, '2014-01-29');
|
||||
INSERT INTO public.test_scores (student, subject, score, test_date) VALUES ('sonia', 'calculus', 70, '2014-01-29');
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3410 (class 2606 OID 1850844)
|
||||
-- Name: test_scores pk_test_scores; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.test_scores
|
||||
ADD CONSTRAINT pk_test_scores PRIMARY KEY (student, subject, test_date);
|
||||
|
||||
|
||||
-- Completed on 2026-01-11 17:44:34
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict XYhHprEBwLNrs6C0UTUr4KIJDbzpD3z6z4Wvdh7qeGQoX177FDq5aBzSJyIqvmD
|
||||
|
||||
Reference in New Issue
Block a user