Updating Ch. 18 psql commands

This commit is contained in:
anthonydb 2021-04-14 21:54:56 -04:00
parent 48a564bc5d
commit 081e26bf46

View File

@ -1,13 +1,9 @@
-- FIRST EDITION FILE; IGNORE ---------------------------------------------------------------------------
-- Practical SQL: A Beginner's Guide to Storytelling with Data, 2nd Edition
--------------------------------------------------------------
-- Practical SQL: A Beginner's Guide to Storytelling with Data
-- by Anthony DeBarros -- by Anthony DeBarros
-- Chapter 18 Code Examples -- Chapter 18 Code Examples
-------------------------------------------------------------- ----------------------------------------------------------------------------
-- Connecting psql to a database on a local server -- Connecting psql to a database on a local server
@ -15,39 +11,40 @@
psql -d [database name] -U [username] psql -d [database name] -U [username]
psql -d analysis -U postgres psql -d analysis -U postgres
-- Changing user and database name -- Connecting psql to a database on a remote server
psql -d [database name] -U [username] -h [host name]
psql -d analysis -U postgres -h example.com
\c [database name] [user name]
\c gis_analysis postgres
-- Listing 18-1: Entering a single-line query in psql -- Listing 18-1: Entering a single-line query in psql
-- Enter this at the psql prompt: -- Enter this at the psql prompt:
SELECT geo_name FROM us_counties_2010 LIMIT 3; SELECT county_name FROM us_counties_pop_est_2019 ORDER BY county_name LIMIT 3;
-- Listing 18-2: Entering a multi-line query in psql -- Listing 18-2: Entering a multi-line query in psql
-- Type each line separately, followed by Enter -- Type each line separately, followed by Enter
SELECT geo_name SELECT county_name
FROM us_counties_2010 FROM us_counties_pop_est_2019
ORDER BY county_name
LIMIT 3; LIMIT 3;
-- Listing 18-3: Showing open parentheses in the psql prompt -- Listing 18-3: Showing open parentheses in the psql prompt
CREATE TABLE wineries ( CREATE TABLE wineries (
id bigint, id bigint,
winery_name varchar(100) winery_name text
); );
-- Listing 18-4: A query with scrolling results -- Listing 18-4: A query with scrolling results
SELECT geo_name FROM us_counties_2010; SELECT county_name FROM us_counties_pop_est_2019 ORDER BY county_name;
-- Listings 18-5 and 18-6: Normal and expanded displays of results -- Listings 18-5 and 18-6: Normal and expanded displays of results
-- Use \x to toggle expanded on/off -- Use \x to toggle expanded on/off
SELECT * FROM grades; SELECT * FROM grades ORDER BY student_id, course_id;
-- Listing 18-7: Importing data using \copy -- Listing 18-7: Importing data using \copy
@ -81,6 +78,11 @@ SELECT * FROM grades;
createdb -U postgres -e box_office createdb -U postgres -e box_office
-- Changing user and database name
\c [database name] [user name]
\c gis_analysis postgres
-- Loading shapefiles into PostgreSQL -- Loading shapefiles into PostgreSQL