Tabs to spaces
This commit is contained in:
parent
aec9b05875
commit
b0f23d78a4
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
CREATE TABLE char_data_types (
|
CREATE TABLE char_data_types (
|
||||||
char_column char(10),
|
char_column char(10),
|
||||||
varchar_column varchar(10),
|
varchar_column varchar(10),
|
||||||
text_column text
|
text_column text
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -22,21 +22,21 @@ CREATE TABLE us_counties_pop_est_2019 (
|
|||||||
state_fips text, -- State FIPS code
|
state_fips text, -- State FIPS code
|
||||||
county_fips text, -- County FIPS code
|
county_fips text, -- County FIPS code
|
||||||
region smallint, -- Region
|
region smallint, -- Region
|
||||||
state_name text, -- State name
|
state_name text, -- State name
|
||||||
county_name text, -- County name
|
county_name text, -- County name
|
||||||
area_land bigint, -- Area (Land) in square meters
|
area_land bigint, -- Area (Land) in square meters
|
||||||
area_water bigint, -- Area (Water) in square meters
|
area_water bigint, -- Area (Water) in square meters
|
||||||
internal_point_lat numeric(10,7), -- Internal point (latitude)
|
internal_point_lat numeric(10,7), -- Internal point (latitude)
|
||||||
internal_point_lon numeric(10,7), -- Internal point (longitude)
|
internal_point_lon numeric(10,7), -- Internal point (longitude)
|
||||||
pop_est_2018 integer, -- 2018-07-01 resident total population estimate
|
pop_est_2018 integer, -- 2018-07-01 resident total population estimate
|
||||||
pop_est_2019 integer, -- 2019-07-01 resident total population estimate
|
pop_est_2019 integer, -- 2019-07-01 resident total population estimate
|
||||||
births_2019 integer, -- Births from 2018-07-01 to 2019-06-30
|
births_2019 integer, -- Births from 2018-07-01 to 2019-06-30
|
||||||
deaths_2019 integer, -- Deaths from 2018-07-01 to 2019-06-30
|
deaths_2019 integer, -- Deaths from 2018-07-01 to 2019-06-30
|
||||||
international_migr_2019 integer, -- Net international migration from 2018-07-01 to 2019-06-30
|
international_migr_2019 integer, -- Net international migration from 2018-07-01 to 2019-06-30
|
||||||
domestic_migr_2019 integer, -- Net domestic migration from 2018-07-01 to 2019-06-30
|
domestic_migr_2019 integer, -- Net domestic migration from 2018-07-01 to 2019-06-30
|
||||||
residual_2019 integer, -- Residual for 2018-07-01 to 2019-06-30
|
residual_2019 integer, -- Residual for 2018-07-01 to 2019-06-30
|
||||||
CONSTRAINT counties_2019_key PRIMARY KEY (state_fips, county_fips)
|
CONSTRAINT counties_2019_key PRIMARY KEY (state_fips, county_fips)
|
||||||
);
|
);
|
||||||
|
|
||||||
SELECT * FROM us_counties_pop_est_2019;
|
SELECT * FROM us_counties_pop_est_2019;
|
||||||
|
|
||||||
@ -46,8 +46,7 @@ SELECT * FROM us_counties_pop_est_2019;
|
|||||||
-- Windows users: Please check the Note on PAGE XXXXXX as well.
|
-- Windows users: Please check the Note on PAGE XXXXXX as well.
|
||||||
|
|
||||||
COPY us_counties_pop_est_2019
|
COPY us_counties_pop_est_2019
|
||||||
-- FROM 'C:\YourDirectory\us_counties_2010.csv'
|
FROM 'C:\YourDirectory\us_counties_pop_est_2019.csv'
|
||||||
FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_pop_est_2019.csv'
|
|
||||||
WITH (FORMAT CSV, HEADER);
|
WITH (FORMAT CSV, HEADER);
|
||||||
|
|
||||||
-- Checking the data
|
-- Checking the data
|
||||||
@ -69,7 +68,7 @@ LIMIT 5;
|
|||||||
|
|
||||||
CREATE TABLE supervisor_salaries (
|
CREATE TABLE supervisor_salaries (
|
||||||
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
town text,
|
town text,
|
||||||
county text,
|
county text,
|
||||||
supervisor text,
|
supervisor text,
|
||||||
start_date text,
|
start_date text,
|
||||||
@ -80,8 +79,7 @@ CREATE TABLE supervisor_salaries (
|
|||||||
-- Listing 5-5: Importing salaries data from CSV to three table columns
|
-- Listing 5-5: Importing salaries data from CSV to three table columns
|
||||||
|
|
||||||
COPY supervisor_salaries (town, supervisor, salary)
|
COPY supervisor_salaries (town, supervisor, salary)
|
||||||
-- FROM 'C:\YourDirectory\supervisor_salaries.csv'
|
FROM 'C:\YourDirectory\supervisor_salaries.csv'
|
||||||
FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/supervisor_salaries.csv'
|
|
||||||
WITH (FORMAT CSV, HEADER);
|
WITH (FORMAT CSV, HEADER);
|
||||||
|
|
||||||
-- Check the data
|
-- Check the data
|
||||||
@ -96,8 +94,7 @@ CREATE TEMPORARY TABLE supervisor_salaries_temp
|
|||||||
(LIKE supervisor_salaries INCLUDING ALL);
|
(LIKE supervisor_salaries INCLUDING ALL);
|
||||||
|
|
||||||
COPY supervisor_salaries_temp (town, supervisor, salary)
|
COPY supervisor_salaries_temp (town, supervisor, salary)
|
||||||
-- FROM 'C:\YourDirectory\supervisor_salaries.csv'
|
FROM 'C:\YourDirectory\supervisor_salaries.csv'
|
||||||
FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/supervisor_salaries.csv'
|
|
||||||
WITH (FORMAT CSV, HEADER);
|
WITH (FORMAT CSV, HEADER);
|
||||||
|
|
||||||
INSERT INTO supervisor_salaries (town, county, supervisor, salary)
|
INSERT INTO supervisor_salaries (town, county, supervisor, salary)
|
||||||
@ -113,8 +110,7 @@ SELECT * FROM supervisor_salaries LIMIT 2;
|
|||||||
-- Listing 5-7: Export an entire table with COPY
|
-- Listing 5-7: Export an entire table with COPY
|
||||||
|
|
||||||
COPY us_counties_pop_est_2019
|
COPY us_counties_pop_est_2019
|
||||||
-- TO 'C:\YourDirectory\us_counties_export.txt'
|
TO 'C:\YourDirectory\us_counties_export.txt'
|
||||||
TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_export.txt'
|
|
||||||
WITH (FORMAT CSV, HEADER, DELIMITER '|');
|
WITH (FORMAT CSV, HEADER, DELIMITER '|');
|
||||||
|
|
||||||
|
|
||||||
@ -122,8 +118,7 @@ WITH (FORMAT CSV, HEADER, DELIMITER '|');
|
|||||||
|
|
||||||
COPY us_counties_pop_est_2019
|
COPY us_counties_pop_est_2019
|
||||||
(county_name, internal_point_lat, internal_point_lon)
|
(county_name, internal_point_lat, internal_point_lon)
|
||||||
-- TO 'C:\YourDirectory\us_counties_latlon_export.txt'
|
TO 'C:\YourDirectory\us_counties_latlon_export.txt'
|
||||||
TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_latlon_export.csv'
|
|
||||||
WITH (FORMAT CSV, HEADER, DELIMITER '|');
|
WITH (FORMAT CSV, HEADER, DELIMITER '|');
|
||||||
|
|
||||||
-- Listing 5-9: Exporting query results with COPY
|
-- Listing 5-9: Exporting query results with COPY
|
||||||
@ -133,6 +128,5 @@ COPY (
|
|||||||
FROM us_counties_pop_est_2019
|
FROM us_counties_pop_est_2019
|
||||||
WHERE county_name ILIKE '%mill%'
|
WHERE county_name ILIKE '%mill%'
|
||||||
)
|
)
|
||||||
-- TO 'C:\YourDirectory\us_counties_mill_export.csv'
|
TO 'C:\YourDirectory\us_counties_mill_export.csv'
|
||||||
TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_mill_export.csv'
|
|
||||||
WITH (FORMAT CSV, HEADER);
|
WITH (FORMAT CSV, HEADER);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user