diff --git a/Chapter_05/Chapter_05.sql b/Chapter_05/Chapter_05.sql index 5d5bd66..4da6cbf 100644 --- a/Chapter_05/Chapter_05.sql +++ b/Chapter_05/Chapter_05.sql @@ -85,7 +85,20 @@ WITH (FORMAT CSV, HEADER); -- Check the data SELECT * FROM supervisor_salaries ORDER BY id LIMIT 2; --- Listing 5-6 Use a temporary table to add a default value to a column during + +-- Listing 5-6: Importing a subset of rows with WHERE + +DELETE FROM supervisor_salaries; + +COPY supervisor_salaries (town, supervisor, salary) +FROM 'C:\YourDirectory\supervisor_salaries.csv' +WITH (FORMAT CSV, HEADER) +WHERE town = 'New Brillig'; + +SELECT * FROM supervisor_salaries; + + +-- Listing 5-7: Use a temporary table to add a default value to a column during -- import DELETE FROM supervisor_salaries; @@ -107,21 +120,21 @@ DROP TABLE supervisor_salaries_temp; SELECT * FROM supervisor_salaries ORDER BY id LIMIT 2; --- Listing 5-7: Export an entire table with COPY +-- Listing 5-8: Export an entire table with COPY COPY us_counties_pop_est_2019 TO 'C:\YourDirectory\us_counties_export.txt' WITH (FORMAT CSV, HEADER, DELIMITER '|'); --- Listing 5-8: Exporting selected columns from a table with COPY +-- Listing 5-9: Exporting selected columns from a table with COPY COPY us_counties_pop_est_2019 (county_name, internal_point_lat, internal_point_lon) TO 'C:\YourDirectory\us_counties_latlon_export.txt' WITH (FORMAT CSV, HEADER, DELIMITER '|'); --- Listing 5-9: Exporting query results with COPY +-- Listing 5-10: Exporting query results with COPY COPY ( SELECT county_name, state_name diff --git a/Chapter_05/supervisor_salaries.csv b/Chapter_05/supervisor_salaries.csv index f0a9a99..b9c7ee8 100644 --- a/Chapter_05/supervisor_salaries.csv +++ b/Chapter_05/supervisor_salaries.csv @@ -1,6 +1,6 @@ town,supervisor,salary Anytown,Jones,67000 -Bumblyburg,Baker,74999 +Bumblyburg,Larry,74999 Moetown,Smith,52100 Bigville,Kao,81500 New Brillig,Carroll,102690