From 081e26bf46803580108e6a460e4f5fcac672a11d Mon Sep 17 00:00:00 2001 From: anthonydb Date: Wed, 14 Apr 2021 21:54:56 -0400 Subject: [PATCH] Updating Ch. 18 psql commands --- Chapter_18/psql_commands.txt | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Chapter_18/psql_commands.txt b/Chapter_18/psql_commands.txt index aa0ef1a..73ee260 100644 --- a/Chapter_18/psql_commands.txt +++ b/Chapter_18/psql_commands.txt @@ -1,13 +1,9 @@ --- FIRST EDITION FILE; IGNORE - - - --------------------------------------------------------------- --- Practical SQL: A Beginner's Guide to Storytelling with Data +--------------------------------------------------------------------------- +-- Practical SQL: A Beginner's Guide to Storytelling with Data, 2nd Edition -- by Anthony DeBarros -- Chapter 18 Code Examples --------------------------------------------------------------- +---------------------------------------------------------------------------- -- Connecting psql to a database on a local server @@ -15,39 +11,40 @@ psql -d [database name] -U [username] 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 -- 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 -- Type each line separately, followed by Enter -SELECT geo_name -FROM us_counties_2010 +SELECT county_name +FROM us_counties_pop_est_2019 +ORDER BY county_name LIMIT 3; - -- Listing 18-3: Showing open parentheses in the psql prompt CREATE TABLE wineries ( id bigint, -winery_name varchar(100) +winery_name text ); -- 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 -- 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 @@ -81,6 +78,11 @@ SELECT * FROM grades; createdb -U postgres -e box_office +-- Changing user and database name + +\c [database name] [user name] +\c gis_analysis postgres + -- Loading shapefiles into PostgreSQL