0% found this document useful (0 votes)
6 views

31309

Practical SQL: A Beginner's Guide to Storytelling with Data by Anthony DeBarros is a comprehensive resource for learning SQL, focusing on data analysis and storytelling techniques. The book covers essential SQL concepts, including database creation, data manipulation, and advanced querying techniques, while providing practical examples and exercises. It is designed for beginners and includes insights from the author's extensive experience in journalism and data analysis.

Uploaded by

zambagaulet2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

31309

Practical SQL: A Beginner's Guide to Storytelling with Data by Anthony DeBarros is a comprehensive resource for learning SQL, focusing on data analysis and storytelling techniques. The book covers essential SQL concepts, including database creation, data manipulation, and advanced querying techniques, while providing practical examples and exercises. It is designed for beginners and includes insights from the author's extensive experience in journalism and data analysis.

Uploaded by

zambagaulet2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Practical SQL A Beginner s Guide to Storytelling

with Data 1st Edition Anthony Debarros pdf


download

https://textbookfull.com/product/practical-sql-a-beginner-s-
guide-to-storytelling-with-data-1st-edition-anthony-debarros/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Practical SQL A Beginner s Guide to Storytelling with


Data 1st Edition Anthony Debarros

https://textbookfull.com/product/practical-sql-a-beginner-s-
guide-to-storytelling-with-data-1st-edition-anthony-debarros-2/

Practical SQL 1st Edition Anthony Debarros

https://textbookfull.com/product/practical-sql-1st-edition-
anthony-debarros/

SQL QuickStart Guide The Simplified Beginner s Guide to


Managing Analyzing and Manipulating Data With SQL 1st
Edition Shields

https://textbookfull.com/product/sql-quickstart-guide-the-
simplified-beginner-s-guide-to-managing-analyzing-and-
manipulating-data-with-sql-1st-edition-shields/

A Beginner s Guide to Working with Astronomical Data


1st Edition Markus Pössel

https://textbookfull.com/product/a-beginner-s-guide-to-working-
with-astronomical-data-1st-edition-markus-possel/
Practical guide to Oracle SQL, T-SQL and MySQL 1st
Edition Preston Zhang

https://textbookfull.com/product/practical-guide-to-oracle-sql-t-
sql-and-mysql-1st-edition-preston-zhang/

Beginner s Guide to Create Models With 3ds Max Ravi


Conor

https://textbookfull.com/product/beginner-s-guide-to-create-
models-with-3ds-max-ravi-conor/

Practical Hive A Guide to Hadoop s Data Warehouse


System 1st Edition Scott Shaw

https://textbookfull.com/product/practical-hive-a-guide-to-
hadoop-s-data-warehouse-system-1st-edition-scott-shaw/

A Beginner s Guide to Circuits Nine Simple Projects


with Lights Sounds and More Dahl

https://textbookfull.com/product/a-beginner-s-guide-to-circuits-
nine-simple-projects-with-lights-sounds-and-more-dahl/

A Beginner s Further Guide to Mathematical Logic 1st


Edition Raymond M. Smullyan

https://textbookfull.com/product/a-beginner-s-further-guide-to-
mathematical-logic-1st-edition-raymond-m-smullyan/
PRACTICAL SQL
A Beginner’s Guide to Storytelling with Data

by Anthony DeBarros

San Francisco
PRACTICAL SQL. Copyright © 2018 by Anthony DeBarros.

All rights reserved. No part of this work may be reproduced or transmitted in any
form or by any means, electronic or mechanical, including photocopying, recording, or
by any information storage or retrieval system, without the prior written permission of
the copyright owner and the publisher.

ISBN-10: 1-59327-827-6
ISBN-13: 978-1-59327-827-4

Publisher: William Pollock


Production Editor: Janelle Ludowise
Cover Illustration: Josh Ellingson
Interior Design: Octopod Studios
Developmental Editors: Liz Chadwick and Annie Choi
Technical Reviewer: Josh Berkus
Copyeditor: Anne Marie Walker
Compositor: Janelle Ludowise
Proofreader: James Fraleigh

For information on distribution, translations, or bulk sales, please contact No Starch


Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; [email protected]
www.nostarch.com

Library of Congress Cataloging-in-Publication Data


Names: DeBarros, Anthony, author.
Title: Practical SQL : a beginner's guide to storytelling with data /
Anthony
DeBarros.
Description: San Francisco : No Starch Press, 2018. | Includes index.
Identifiers: LCCN 2018000030 (print) | LCCN 2017043947 (ebook) | ISBN
9781593278458 (epub) | ISBN 1593278454 (epub) | ISBN 9781593278274
(paperback) | ISBN 1593278276 (paperback) | ISBN 9781593278458 (ebook)
Subjects: LCSH: SQL (Computer program language) | Database design. |
BISAC:
COMPUTERS / Programming Languages / SQL. | COMPUTERS / Database
Management
/ General. | COMPUTERS / Database Management / Data Mining.
Classification: LCC QA76.73.S67 (print) | LCC QA76.73.S67 D44 2018
(ebook) |
DDC 005.75/6--dc23
LC record available at https://lccn.loc.gov/2018000030

No Starch Press and the No Starch Press logo are registered trademarks of No Starch
Press, Inc. Other product and company names mentioned herein may be the
trademarks of their respective owners. Rather than use a trademark symbol with every
occurrence of a trademarked name, we are using the names only in an editorial fashion
and to the benefit of the trademark owner, with no intention of infringement of the
trademark.

The information in this book is distributed on an “As Is” basis, without warranty.
While every precaution has been taken in the preparation of this work, neither the
author nor No Starch Press, Inc. shall have any liability to any person or entity with
respect to any loss or damage caused or alleged to be caused directly or indirectly by
the information contained in it.
About the Author
Anthony DeBarros is an award-winning journalist who has combined
avid interests in data analysis, coding, and storytelling for much of his
career. He spent more than 25 years with the Gannett company,
including the Poughkeepsie Journal, USA TODAY, and Gannett Digital.
He is currently senior vice president for content and product
development for a publishing and events firm and lives and works in the
Washington, D.C., area.
About the Technical Reviewer
Josh Berkus is a “hacker emeritus” for the PostgreSQL Project, where
he served on the Core Team for 13 years. He was also a database
consultant for 15 years, working with PostgreSQL, MySQL, CitusDB,
Redis, CouchDB, Hadoop, and Microsoft SQL Server. Josh currently
works as a Kubernetes community manager at Red Hat, Inc.
BRIEF CONTENTS
Foreword by Sarah Frostenson
Acknowledgments
Introduction
Chapter 1: Creating Your First Database and Table
Chapter 2: Beginning Data Exploration with SELECT
Chapter 3: Understanding Data Types
Chapter 4: Importing and Exporting Data
Chapter 5: Basic Math and Stats with SQL
Chapter 6: Joining Tables in a Relational Database
Chapter 7: Table Design That Works for You
Chapter 8: Extracting Information by Grouping and Summarizing
Chapter 9: Inspecting and Modifying Data
Chapter 10: Statistical Functions in SQL
Chapter 11: Working with Dates and Times
Chapter 12: Advanced Query Techniques
Chapter 13: Mining Text to Find Meaningful Data
Chapter 14: Analyzing Spatial Data with PostGIS
Chapter 15: Saving Time with Views, Functions, and Triggers
Chapter 16: Using PostgreSQL from the Command Line
Chapter 17: Maintaining Your Database
Chapter 18: Identifying and Telling the Story Behind Your Data
Appendix: Additional PostgreSQL Resources
Index
CONTENTS IN DETAIL
FOREWORD by Sarah Frostenson

ACKNOWLEDGMENTS

INTRODUCTION
What Is SQL?
Why Use SQL?
About This Book
Using the Book’s Code Examples
Using PostgreSQL
Installing PostgreSQL
Working with pgAdmin
Alternatives to pgAdmin
Wrapping Up

1
CREATING YOUR FIRST DATABASE AND TABLE
Creating a Database
Executing SQL in pgAdmin
Connecting to the Analysis Database
Creating a Table
The CREATE TABLE Statement
Making the teachers Table
Inserting Rows into a Table
The INSERT Statement
Viewing the Data
When Code Goes Bad
Formatting SQL for Readability
Wrapping Up
Try It Yourself

2
BEGINNING DATA EXPLORATION WITH SELECT
Basic SELECT Syntax
Querying a Subset of Columns
Using DISTINCT to Find Unique Values
Sorting Data with ORDER BY
Filtering Rows with WHERE
Using LIKE and ILIKE with WHERE
Combining Operators with AND and OR
Putting It All Together
Wrapping Up
Try It Yourself

3
UNDERSTANDING DATA TYPES
Characters
Numbers
Integers
Auto-Incrementing Integers
Decimal Numbers
Choosing Your Number Data Type
Dates and Times
Using the interval Data Type in Calculations
Miscellaneous Types
Transforming Values from One Type to Another with CAST
CAST Shortcut Notation
Wrapping Up
Try It Yourself

4
IMPORTING AND EXPORTING DATA
Working with Delimited Text Files
Quoting Columns that Contain Delimiters
Handling Header Rows
Using COPY to Import Data
Importing Census Data Describing Counties
Creating the us_counties_2010 Table
Census Columns and Data Types
Performing the Census Import with COPY
Importing a Subset of Columns with COPY
Adding a Default Value to a Column During Import
Using COPY to Export Data
Exporting All Data
Exporting Particular Columns
Exporting Query Results
Importing and Exporting Through pgAdmin
Wrapping Up
Try It Yourself

5
BASIC MATH AND STATS WITH SQL
Math Operators
Math and Data Types
Adding, Subtracting, and Multiplying
Division and Modulo
Exponents, Roots, and Factorials
Minding the Order of Operations
Doing Math Across Census Table Columns
Adding and Subtracting Columns
Finding Percentages of the Whole
Tracking Percent Change
Aggregate Functions for Averages and Sums
Finding the Median
Finding the Median with Percentile Functions
Median and Percentiles with Census Data
Finding Other Quantiles with Percentile Functions
Creating a median() Function
Finding the Mode
Wrapping Up
Try It Yourself

6
JOINING TABLES IN A RELATIONAL DATABASE
Linking Tables Using JOIN
Relating Tables with Key Columns
Querying Multiple Tables Using JOIN
JOIN Types
JOIN
LEFT JOIN and RIGHT JOIN
FULL OUTER JOIN
CROSS JOIN
Using NULL to Find Rows with Missing Values
Three Types of Table Relationships
One-to-One Relationship
One-to-Many Relationship
Many-to-Many Relationship
Selecting Specific Columns in a Join
Simplifying JOIN Syntax with Table Aliases
Joining Multiple Tables
Performing Math on Joined Table Columns
Wrapping Up
Try It Yourself

7
TABLE DESIGN THAT WORKS FOR YOU
Naming Tables, Columns, and Other Identifiers
Using Quotes Around Identifiers to Enable Mixed Case
Pitfalls with Quoting Identifiers
Guidelines for Naming Identifiers
Controlling Column Values with Constraints
Primary Keys: Natural vs. Surrogate
Foreign Keys
Automatically Deleting Related Records with CASCADE
The CHECK Constraint
The UNIQUE Constraint
The NOT NULL Constraint
Removing Constraints or Adding Them Later
Speeding Up Queries with Indexes
B-Tree: PostgreSQL’s Default Index
Considerations When Using Indexes
Wrapping Up
Try It Yourself

8
EXTRACTING INFORMATION BY GROUPING AND
SUMMARIZING
Creating the Library Survey Tables
Creating the 2014 Library Data Table
Creating the 2009 Library Data Table
Exploring the Library Data Using Aggregate Functions
Counting Rows and Values Using count()
Finding Maximum and Minimum Values Using max() and
min()
Aggregating Data Using GROUP BY
Wrapping Up
Try It Yourself
9
INSPECTING AND MODIFYING DATA
Importing Data on Meat, Poultry, and Egg Producers
Interviewing the Data Set
Checking for Missing Values
Checking for Inconsistent Data Values
Checking for Malformed Values Using length()
Modifying Tables, Columns, and Data
Modifying Tables with ALTER TABLE
Modifying Values with UPDATE
Creating Backup Tables
Restoring Missing Column Values
Updating Values for Consistency
Repairing ZIP Codes Using Concatenation
Updating Values Across Tables
Deleting Unnecessary Data
Deleting Rows from a Table
Deleting a Column from a Table
Deleting a Table from a Database
Using Transaction Blocks to Save or Revert Changes
Improving Performance When Updating Large Tables
Wrapping Up
Try It Yourself

10
STATISTICAL FUNCTIONS IN SQL
Creating a Census Stats Table
Measuring Correlation with corr(Y, X)
Checking Additional Correlations
Predicting Values with Regression Analysis
Finding the Effect of an Independent Variable with r-squared
Creating Rankings with SQL
Ranking with rank() and dense_rank()
Ranking Within Subgroups with PARTITION BY
Calculating Rates for Meaningful Comparisons
Wrapping Up
Try It Yourself

11
WORKING WITH DATES AND TIMES
Data Types and Functions for Dates and Times
Manipulating Dates and Times
Extracting the Components of a timestamp Value
Creating Datetime Values from timestamp Components
Retrieving the Current Date and Time
Working with Time Zones
Finding Your Time Zone Setting
Setting the Time Zone
Calculations with Dates and Times
Finding Patterns in New York City Taxi Data
Finding Patterns in Amtrak Data
Wrapping Up
Try It Yourself

12
ADVANCED QUERY TECHNIQUES
Using Subqueries
Filtering with Subqueries in a WHERE Clause
Creating Derived Tables with Subqueries
Joining Derived Tables
Generating Columns with Subqueries
Subquery Expressions
Common Table Expressions
Cross Tabulations
Installing the crosstab() Function
Tabulating Survey Results
Tabulating City Temperature Readings
Reclassifying Values with CASE
Using CASE in a Common Table Expression
Wrapping Up
Try It Yourself

13
MINING TEXT TO FIND MEANINGFUL DATA
Formatting Text Using String Functions
Case Formatting
Character Information
Removing Characters
Extracting and Replacing Characters
Matching Text Patterns with Regular Expressions
Regular Expression Notation
Turning Text to Data with Regular Expression Functions
Using Regular Expressions with WHERE
Additional Regular Expression Functions
Full Text Search in PostgreSQL
Text Search Data Types
Creating a Table for Full Text Search
Searching Speech Text
Ranking Query Matches by Relevance
Wrapping Up
Try It Yourself

14
ANALYZING SPATIAL DATA WITH POSTGIS
Installing PostGIS and Creating a Spatial Database
The Building Blocks of Spatial Data
Two-Dimensional Geometries
Well-Known Text Formats
A Note on Coordinate Systems
Spatial Reference System Identifier
PostGIS Data Types
Creating Spatial Objects with PostGIS Functions
Creating a Geometry Type from Well-Known Text
Creating a Geography Type from Well-Known Text
Point Functions
LineString Functions
Polygon Functions
Analyzing Farmers’ Markets Data
Creating and Filling a Geography Column
Adding a GiST Index
Finding Geographies Within a Given Distance
Finding the Distance Between Geographies
Working with Census Shapefiles
Contents of a Shapefile
Loading Shapefiles via the GUI Tool
Exploring the Census 2010 Counties Shapefile
Performing Spatial Joins
Exploring Roads and Waterways Data
Joining the Census Roads and Water Tables
Finding the Location Where Objects Intersect
Wrapping Up
Try It Yourself

15
SAVING TIME WITH VIEWS, FUNCTIONS, AND TRIGGERS
Using Views to Simplify Queries
Creating and Querying Views
Inserting, Updating, and Deleting Data Using a View
Programming Your Own Functions
Creating the percent_change() Function
Using the percent_change() Function
Updating Data with a Function
Using the Python Language in a Function
Automating Database Actions with Triggers
Logging Grade Updates to a Table
Automatically Classifying Temperatures
Wrapping Up
Try It Yourself

16
USING POSTGRESQL FROM THE COMMAND LINE
Setting Up the Command Line for psql
Windows psql Setup
macOS psql Setup
Linux psql Setup
Working with psql
Launching psql and Connecting to a Database
Getting Help
Changing the User and Database Connection
Running SQL Queries on psql
Navigating and Formatting Results
Meta-Commands for Database Information
Importing, Exporting, and Using Files
Additional Command Line Utilities to Expedite Tasks
Adding a Database with createdb
Loading Shapefiles with shp2pgsql
Wrapping Up
Try It Yourself
17
MAINTAINING YOUR DATABASE
Recovering Unused Space with VACUUM
Tracking Table Size
Monitoring the autovacuum Process
Running VACUUM Manually
Reducing Table Size with VACUUM FULL
Changing Server Settings
Locating and Editing postgresql.conf
Reloading Settings with pg_ctl
Backing Up and Restoring Your Database
Using pg_dump to Back Up a Database or Table
Restoring a Database Backup with pg_restore
Additional Backup and Restore Options
Wrapping Up
Try It Yourself

18
IDENTIFYING AND TELLING THE STORY BEHIND YOUR
DATA
Start with a Question
Document Your Process
Gather Your Data
No Data? Build Your Own Database
Assess the Data’s Origins
Interview the Data with Queries
Consult the Data’s Owner
Identify Key Indicators and Trends over Time
Ask Why
Communicate Your Findings
Wrapping Up
Try It Yourself
APPENDIX
ADDITIONAL POSTGRESQL RESOURCES
PostgreSQL Development Environments
PostgreSQL Utilities, Tools, and Extensions
PostgreSQL News
Documentation

INDEX
FOREWORD

When people ask which programming language I learned first, I often


absent-mindedly reply, “Python,” forgetting that it was actually with
SQL that I first learned to write code. This is probably because learning
SQL felt so intuitive after spending years running formulas in Excel
spreadsheets. I didn’t have a technical background, but I found SQL’s
syntax, unlike that of many other programming languages,
straightforward and easy to implement. For example, you run SELECT *
on a SQL table to make every row and column appear. You simply use
the JOIN keyword to return rows of data from different related tables,
which you can then further group, sort, and analyze.
I’m a graphics editor, and I’ve worked as a developer and journalist at
a number of publications, including POLITICO, Vox, and USA TODAY.
My daily responsibilities involve analyzing data and creating
visualizations from what I find. I first used SQL when I worked at The
Chronicle of Higher Education and its sister publication, The Chronicle of
Philanthropy. Our team analyzed data ranging from nonprofit financials
to faculty salaries at colleges and universities. Many of our projects
included as much as 20 years’ worth of data, and one of my main tasks
was to import all that data into a SQL database and analyze it. I had to
calculate the percent change in fund­raising dollars at a nonprofit or find
the median endowment size at a university to measure an institution’s
performance.
I discovered SQL to be a powerful language, one that fundamentally
shaped my understanding of what you can—and can’t—do with data.
SQL excels at bringing order to messy, large data sets and helps you
discover how different data sets are related. Plus, its queries and
functions are easy to reuse within the same project or even in a different
database.
This leads me to Practical SQL. Looking back, I wish I’d read
Chapter 4 on “Importing and Exporting Data” so I could have
understood the power of bulk imports instead of writing long,
cumbersome INSERT statements when filling a table. The statistical
capabilities of PostgreSQL, covered in Chapters 5 and 10 in this book,
are also something I wish I had grasped earlier, as my data analysis often
involves calculating the percent change or finding the average or
median values. I’m embarrassed to say that I didn’t know how
percentile_cont(), covered in Chapter 5, could be used to easily calculate
a median in PostgresSQL—with the added bonus that it also finds your
data’s natural breaks or quantiles.
But at that stage in my career, I was only scratching the surface of
SQL’s capabilities. It wasn’t until 2014, when I became a data developer
at Gannett Digital on a team led by Anthony DeBarros, that I learned to
use PostgreSQL. I began to understand just how enormously powerful
SQL was for creating a reproducible and sustainable workflow.
When I met Anthony, he had been working at USA TODAY and
other Gannett properties for more than 20 years, where he had led
teams that built databases and published award-winning investigations.
Anthony was able to show me the ins and outs of our team’s databases in
addition to teaching me how to properly build and maintain my own. It
was through working with Anthony that I truly learned how to code.
One of the first projects Anthony and I collaborated on was the 2014
U.S. midterm elections. We helped build an election forecast data
visualization to show USA TODAY readers the latest polling averages,
campaign finance data, and biographical information for more than
1,300 candidates in more than 500 congressional and gubernatorial
races. Building our data infrastructure was a complex, multistep process
powered by a PostgreSQL database at its heart.
Anthony taught me how to write code that funneled all the data from
our sources into a half-dozen tables in PostgreSQL. From there, we
could query the data into a format that would power the maps, charts,
and front-end presentation of our election forecast.
Around this time, I also learned one of my favorite things about
PostgreSQL—its powerful suite of geographic functions (Chapter 14 in
this book). By adding the PostGIS extension to the database, you can
create spatial data that you can then export as GeoJSON or as a
shapefile, a format that is easy to map. You can also perform complex
spatial analysis, like calculating the distance between two points or
finding the density of schools or, as Anthony shows in the chapter, all
the farmers’ markets in a given radius.
It’s a skill I’ve used repeatedly in my career. For example, I used it to
build a data set of lead exposure risk at the census-tract level while at
Vox, which I consider one of my crowning PostGIS achievements. Using
this database, I was able to create a data set of every U.S. Census tract
and its corresponding lead exposure risk in a spatial format that could
be easily mapped at the national level.
With so many different programming languages available—more
than 200, if you can believe it—it’s truly overwhelming to know where
to begin. One of the best pieces of advice I received when first starting
to code was to find an inefficiency in my workflow that could be
improved by coding. In my case, it was building a database to easily
query a project’s data. Maybe you’re in a similar boat or maybe you just
want to know how to analyze large data sets.
Regardless, you’re probably looking for a no-nonsense guide that
skips the programming jargon and delves into SQL in an easy-to-
understand manner that is both practical and, more importantly,
applicable. And that’s exactly what Practical SQL does. It gets away from
programming theory and focuses on teaching SQL by example, using
real data sets you’ll likely encounter. It also doesn’t shy away from
showing you how to deal with annoying messy data pitfalls: misspelled
names, missing values, and columns with unsuitable data types. This is
important because, as you’ll quickly learn, there’s no such thing as clean
data.
Over the years, my role as a data journalist has evolved. I build fewer
databases now and build more maps. I also report more. But the core
requirement of my job, and what I learned when first learning SQL,
remains the same: know thy data and to thine own data be true. In other
words, the most important aspect of working with data is being able to
understand what’s in it.
You can’t expect to ask the right questions of your data or tell a
compelling story if you don’t understand how to best analyze it.
Fortunately, that’s where Practical SQL comes in. It’ll teach you the
fundamentals of working with data so that you can discover your own
stories and insights.

Sarah Frostenson
Graphics Editor at POLITICO
ACKNOWLEDGMENTS

Practical SQL is the work of many hands. My thanks, first, go to the team
at No Starch Press. Thanks to Bill Pollock and Tyler Ortman for
capturing the vision and sharpening the initial concept; to
developmental editors Annie Choi and Liz Chadwick for refining each
chapter; to copyeditor Anne Marie Walker for polishing the final drafts
with an eagle eye; and to production editor Janelle Ludowise for laying
out the book and keeping the process well organized.
Josh Berkus, Kubernetes community manager for Red Hat, Inc.,
served as our technical reviewer. To work with Josh was to receive a
master class in SQL and PostgreSQL. Thank you, Josh, for your
patience and high standards.
Thank you to Investigative Reporters and Editors (IRE) and its
members and staff past and present for training journalists to find great
stories in data. IRE is where I got my start with SQL and data
journalism.
During my years at USA TODAY, many colleagues either taught me
SQL or imparted memorable lessons on data analysis. Special thanks to
Paul Overberg for sharing his vast knowledge of demographics and the
U.S. Census, to Lou Schilling for many technical lessons, to
Christopher Schnaars for his SQL expertise, and to Sarah Frostenson
for graciously agreeing to write the book’s foreword.
My deepest appreciation goes to my dear wife, Elizabeth, and our
sons. Thank you for making every day brighter and warmer, for your
love, and for bearing with me as I completed this book.
INTRODUCTION

Shortly after joining the staff of USA TODAY I received a data set I
would analyze almost every week for the next decade. It was the weekly
Best-Selling Books list, which ranked the nation’s top-selling books
based on confidential sales data. The list not only produced an endless
stream of story ideas to pitch, but it also captured the zeitgeist of
America in a singular way.
For example, did you know that cookbooks sell a bit more during the
week of Mother’s Day, or that Oprah Winfrey turned many obscure
writers into number one best-selling authors just by having them on her
show? Week after week, the book list editor and I pored over the sales
figures and book genres, ranking the data in search of the next headline.
Rarely did we come up empty: we chronicled everything from the
rocket-rise of the blockbuster Harry Potter series to the fact that Oh, the
Places You’ll Go! by Dr. Seuss has become a perennial gift for new
graduates.
My technical companion during this time was the database
programming language SQL (for Structured Query Language). Early on, I
convinced USA TODAY’s IT department to grant me access to the
SQL-based database system that powered our book list application.
Using SQL, I was able to unlock the stories hidden in the database,
which contained titles, authors, genres, and various codes that defined
the publishing world. Analyzing data with SQL to discover interesting
stories is exactly what you’ll learn to do using this book.

What Is SQL?
SQL is a widely used programming language that allows you to define
and query databases. Whether you’re a marketing analyst, a journalist,
or a researcher mapping neurons in the brain of a fruit fly, you’ll benefit
from using SQL to manage database objects as well as create, modify,
explore, and summarize data.
Because SQL is a mature language that has been around for decades,
it’s deeply ingrained in many modern systems. A pair of IBM researchers
first outlined the syntax for SQL (then called SEQUEL) in a 1974
paper, building on the theoretical work of the British computer scientist
Edgar F. Codd. In 1979, a precursor to the database company Oracle
(then called Relational Software) became the first to use the language in
a commercial product. Today, it continues to rank as one of the most-
used computer languages in the world, and that’s unlikely to change
soon.
SQL comes in several variants, which are generally tied to specific
database systems. The American National Standards Institute (ANSI)
and International Organization for Standardization (ISO), which set
standards for products and technologies, provide standards for the
language and shepherd revisions to it. The good news is that the
variants don’t stray far from the standard, so once you learn the SQL
conventions for one database, you can transfer that knowledge to other
systems.

Why Use SQL?


So why should you use SQL? After all, SQL is not usually the first tool
people choose when they’re learning to analyze data. In fact, many
people start with Microsoft Excel spreadsheets and their assortment of
analytic functions. After working with Excel, they might graduate to
Access, the database system built into Microsoft Office, which has a
graphical query interface that makes it easy to get work done, making
SQL skills optional.
But as you might know, Excel and Access have their limits. Excel
currently allows 1,048,576 rows maximum per worksheet, and Access
limits database size to two gigabytes and limits columns to 255 per
table. It’s not uncommon for data sets to surpass those limits,
particularly when you’re working with data dumped from government
systems. The last obstacle you want to discover while facing a deadline
is that your database system doesn’t have the capacity to get the job
done.
Using a robust SQL database system allows you to work with
terabytes of data, multiple related tables, and thousands of columns. It
gives you improved programmatic control over the structure of your
data, leading to efficiency, speed, and—most important—accuracy.
SQL is also an excellent adjunct to programming languages used in
the data sciences, such as R and Python. If you use either language, you
can connect to SQL databases and, in some cases, even incorporate
SQL syntax directly into the language. For people with no background
in programming languages, SQL often serves as an easy-to-understand
introduction into concepts related to data structures and programming
logic.
Additionally, knowing SQL can help you beyond data analysis. If you
delve into building online applications, you’ll find that databases provide
the backend power for many common web frameworks, interactive
maps, and content management systems. When you need to dig beneath
the surface of these applications, SQL’s capability to manipulate data
and databases will come in very handy.

About This Book


Practical SQL is for peoplewho encounter data in their everyday lives
and want to learn how to analyze and transform it. To this end, I discuss
real-world data and scenarios, such as U.S. Census demographics, crime
statistics, and data about taxi rides in New York City. Along with
information about databases and code, you’ll also learn tips on how to
analyze and acquire data as well as other valuable insights I’ve
accumulated throughout my career. I won’t focus on setting up servers
or other tasks typically handled by a database administrator, but the
SQL and PostgreSQL fundamentals you learn in this book will serve
you well if you intend to go that route.
I’ve designed the exercises for beginner SQL coders but will assume
that you know your way around your computer, including how to install
programs, navigate your hard drive, and download files from the
internet. Although many chapters in this book can stand alone, you
should work through the book sequentially to build on the
fundamentals. Some data sets used in early chapters reappear later in the
book, so following the book in order will help you stay on track.
Practical SQL starts with the basics of databases, queries, tables, and
data that are common to SQL across many database systems. Chapters
13 to 17 cover topics more specific to PostgreSQL, such as full text
search and GIS. The following table of contents provides more detail
about the topics discussed in each chapter:

Chapter 1: Creating Your First Database and Table introduces


PostgreSQL, the pgAdmin user interface, and the code for loading a
simple data set about teachers into a new database.
Chapter 2: Beginning Data Exploration with SELECT explores
basic SQL query syntax, including how to sort and filter data.
Chapter 3: Understanding Data Types explains the definitions for
setting columns in a table to hold specific types of data, from text to
dates to various forms of numbers.
Chapter 4: Importing and Exporting Data explains how to use
SQL commands to load data from external files and then export it.
You’ll load a table of U.S. Census population data that you’ll use
throughout the book.
Exploring the Variety of Random
Documents with Different Content
differences; some tanners prefer to split after two days, others after
two weeks in tan. Much depends upon the nature of the tan and the
strength of the liquors.
For this class of work, flat, spready and evenly grown cowhides are
obviously the most suitable material, and are invariably used. It is
important, however, that the grain be good, and free from scratches
and similar defects. The tannage must be sweet and mellow, i.e.
contain no acid and little astringent tan. Hence myrabolans and
gambier have always been the favourite tanning materials. A soft
and mellow tannage is the more important, inasmuch as the leather
is not heavily stuffed with grease in finishing. These types of method
for tanning split hides will now be outlined, and the nature of the
currying then indicated.
Type 1.—In this a long mellow liming of 15-16 days is given, much
like that described for harness leather in Section III., p. 72, Type 3.
Only lime is used, but the liquors are not allowed to get dirty. The
three-pit system is much the best. The hides are trimmed at the
rounding tables, and then bated in hen or pigeon dung for three
days at 75°-85° F. The deliming is commenced by washing in tepid
water before bating, and is completed by a bath of boric acid, using
up to 30 lbs. acid per 100 hides as necessary. In this and other
processes for split hides it is essential to obtain all the lime out, but
to do no plumping with acid. Lactic acid may also be used, but it is
not so convenient to hit the neutral point with it.
The tannage consists of oak bark and myrabs together with gambier.
These may be partly replaced by Natal bark, valonia, and quebracho
respectively. It is sometimes desired to have a smooth finish, but
sometimes to work up a "grain." In the latter case the hides are first
put through colouring pits containing fresh leach liquor. In these
they are constantly handled for a few hours. A little experience
indicates which leach liquor will serve the purpose. The hides then
go through the "green handlers" (8°-20°) in two weeks. The liquor is
the old forward handler liquor made up with gambier. The hides may
be sammed and split up at this stage, but the heavier goods may be
tanned further. These heavies and the grains of the split hides now
go through the "forward handlers" (20°-40°) for four weeks, and the
heaviest goods given two layers (40°) of two weeks each, and
making ten in all.
Type 2.—In this a shorter liming of 8-9 days is given with the help of
sulphide. No dung bate is used, but the goods are washed with
water and bated with ammonium chloride and boric acid. The
tannage is chiefly of myrabs, but some valonia or Natal bark may be
used together with chestnut extract and some quebracho. Gambier
is used in the early liquors. The goods are coloured off in drum or
paddle and tanned in several sets of handlers, viz. green handlers
(15°-35°) three or four days; second handlers (35°-60°) two weeks;
forward handlers (60°-80°) 1½ weeks; and floaters (80°-90°) for
three weeks. The tannage is thus 6½ weeks in all. The arrangement
of pits is a matter of local convenience, and the number of sets of
equal strength is determined by the number of hides being tanned.
The hides are split green or after passing through the green set.
After tanning they are oiled with cod oil and dried out.
Type 3 is illustrated by American methods. The goods are tacked on
laths or racks with copper nails in order to ensure smooth grain.
They are then suspended in tan liquors. The tannage is largely with
gambier and in weak liquors, which also help to give smooth grain.
The tendency is to employ handler rounds involving a rather large
number of pits, and to work these on the press system. Handling is
also saved by plumping the liquors instead of shifting the goods
forward, and by rocking the suspenders instead of handling up and
down. The hides are split after about a month, and the heavier
grains laid away in hemlock liquors.
Type 4.—This is a rapid process throughout. The hides are limed in
6-7 days with the help of sulphide, and "bated" by washing in warm
water and then in cold to which hydrochloric acid is gradually added,
finishing off again in tepid water. The hides are now coloured off in
paddles, put through a small handler round (11°-20°) for half a
week, and then split. The grains are drum tanned in a mixture of
chestnut and quebracho extract, over a period of about three days in
which the liquor is strengthened gradually from 30° to 50°. The
fleshes are drum tanned with the old grain liquors after
strengthening with quebracho.
The split hide grains for bag work, after tanning, are drummed in
sumach, rinsed, drained, and oiled up to dry out, with some setting
out. After wetting back they are shaved if necessary, hand scoured,
and heavily sumached again to get a light even colour. The goods
are slicked out, oiled up to samm, reset and dried out. They are next
stained, sammed, printed by machine, dubbined or tallowed,
"grained" (see Part II., Section I., p. 97), brushed and rubbed with
flannel.

REFERENCE.

Bennett, "Manufacture of Leather," pp. 202, 308.

SECTION X.—PICKING BAND BUTTS

It is the paradox of vegetable tannage that the less the pelt is


tanned the stronger is the leather produced. The manufacture of
butts for picking bands affords a good illustration. What is required is
a leather of maximum toughness, pliability and durability. Any factor
reducing the tensile strength of the leather is fatal. Hence, compared
with most other tannages, picking band butts are under-tanned. To
ensure the desired softness and pliability, moreover, it is necessary
to have a mellow liming, rather heavy bating, and a soft mellow
tannage in sweet and weak liquors. The required durability and the
necessity for weak liquors both point to oak bark as the most
suitable tanning material, assisted by some gambier in the early
stages.
A good quality hide is chosen, and given a long and mellow liming of
about 15-16 days. The one-pit system may be used, and the hides
are put into an old lime for about five days with frequent handling
and then placed in a new lime which is made up in a pit containing
about a foot depth of the old liquor. After about twelve days another
⅓ cwt. of lime may be added.
After unhairing and fleshing the goods are bated in pigeon dung for
four days at a temperature of about 78° F., handling twice on the
first and last days. The bating is stopped and the deliming
completed by paddling with boric acid (15 lbs. per 100 butts).
The tannage is commenced by paddling in a spent handler liquor
(4°) to which a little gambier has been added. The butts then go
through the first handlers (5°-15°), which are rounds of ten pits in
which the goods are handled every day in the first week, and
alternate days in the second week, and are shifted forward twice a
week in the next pit. The goods are therefore in this set for five
weeks. Gambier is added to these liquors as needed. The butts next
pass to duster rounds of four pits, in which they are dusted down in
a liquor of 20° for four weeks with 1-2 cwt. of oak bark. The liquor is
obtained from the leaches, and afterwards run alternately to the
leaches and to the first handlers. As many as six layers are now
given of 20°-25° strength, in which the butts are dusted down with
2-3 cwt. oak bark for three weeks. The layer liquors are received
from and returned to the leaches, which are made from the
"fishings" from the layers. The tannage lasts, therefore, 27 weeks, of
which 18 weeks (two-thirds) are in layers.
Shorter tannages are now often given, using stronger liquors, much
as in ordinary dressing leather.
The tanned butts are rough dried, and then wet in for shaving. They
are thoroughly scoured, flesh and grain. They are next drummed for
three-quarters of an hour in sumach, struck out and hung up to
samm. Hand stuffing is best, to avoid any tendering owing to high
temperature, but drum stuffing is also used. After setting out and
stoning on the grain they are stuffed with warm cod oil and laid
away in grease for several weeks, re-oiling occasionally. They may
be stained before stuffing.

REFERENCE.

Bennett, "Manufacture of Leather," pp. 203, 310.

PART II.—SKINS FOR LIGHT LEATHERS

SECTION I.—PRINCIPLES AND GENERAL METHODS OF


LIGHT LEATHER MANUFACTURE

The term "skin," like the term "hide," in its widest sense applies to
the natural covering for the body of any animal, but is generally
used with a narrower meaning in which it applies only to the
covering of the smaller animals. Thus we speak of sheep skins, goat
skins, seal skins, pig skins, deer skins, and porpoise skins. It is in
this sense that it will be used in this volume. The treatment of such
skins to fit them for useful purposes comprises the light leather
trade. Whilst this branch of the leather industry is certainly
utilitarian, the artistic element is a great deal more prominent in it
than in the heavy leather branch. Thus the light leathers are often
dyed and artistically finished, and their final purposes (such as fancy
goods, upholstery, bookbinding, slippers, etc.) have rather more of
the element of luxury than of essential utility. The total weight and
value of the skins prepared, and of the materials used in their
preparation, are naturally considerably smaller than those of the
heavy leather trade. In the latter, moreover, one has to consider the
purpose in view from the very commencement of manufacture and
vary the process accordingly, but in light leather manufacture one
aims rather, in the factory, at a type of leather such as morocco
leather, and only after manufacture is it fitted to such purposes as
may be particularly suited to the actual result. These results depend
very largely upon the "grain pattern" which is natural to the skin of
any one species of animals. Hence in Part II. of this volume it has
been found most convenient to deal with the different classes of
skins in different sections. Just as the hides of ox and heifer were
much the most numerous and important of hides, so also naturally
are sheepskins the most prominent section of the raw material of
the light leather trade. This is the more true because the skin is
valued for its wool as well as for its pelt; indeed, the wool is often
considered of primary importance, and receives first consideration in
fellmongering. Unfortunately for the light leather trade, sheepskins,
though most numerous, do not give the best class of light leather,
the quality being easily surpassed in strength, beauty and durability
by the leather from goat or seal skins.
In the wet work for the preparation of skins for tannage much the
same general principles and methods are embodied as in the case of
hides, but with appropriate modifications. As soft leathers are chiefly
wanted, a mellow liming is quite the usual requirement for all skins.
It is also usual to have a long liming, for some skins (like those of
sheep and seal) have much natural fat which needs the saponifying
influence of lime and lipolytic action of the enzymes of the lime
liquors; whilst other skins (like those of goat and calf) are very close
textured and need the plumping action of the lime and a certain
solution of interfibrillar substance. In consequence of the long
mellow liming, sulphides are not usually necessary, and indeed
sodium sulphide is not usually desirable, on account of its tendency
to make the grain harsh. It is used, however, for unwoolling
sheepskins, in such a manner that the grain is not touched. Similarly
caustic soda is seldom required, and the yield of pelt by weight is
usually a small consideration. Systems of liming show some variety.
The one-pit system is very common, and is less objectionable for a
long mellow liming, but rounds of several pits are also used, and in
some cases even more than one round. This is obviously conducive
to regularity of treatment, and as the work involved in shifting the
goods is much less laborious than in the case of heavy ox hides, it
would seem a preferable alternative. The depilation of sheepskins
involves very special methods of treatment (sweating and painting)
on account of the importance and value of the wool, the quality and
value of which would be impaired by putting the skins through
ordinary lime liquors. The pelts, however, are limed after unwoolling.
In deliming light leathers the process of puering is widely used (see
p. 25). This consists in immersing the skins after depilation in a
warm fermenting infusion of dog-dung. In principle this disgusting
process presents a close analogy with bating, and indeed the two
terms are both used somewhat loosely, but there are nevertheless
several points in which the two processes are radically different. The
dog-dung puer is a process carried out at a higher temperature than
the fowl-dung bate; it is also a much quicker process, and the
infusion employed is generally more concentrated. Whilst the fowl-
dung bate is always slightly alkaline to phenolphthalein the dog-
dung puer is always acid to this indicator, and the course of the
puering may be conveniently followed by testing the pelts with it.
The mechanism of the two processes is also probably somewhat
different. The mechanism of the dog-dung puer has been largely
made clear by the researches of Wood and others, and been found
due partly to a deliming action by the amine salts of weak organic
acids and partly to the action of enzymes from a bacillus of the coli
class, which received the name of B. erodiens, and which effects a
solvent action on the interfibrillar substance. As we have noted (Part
I., Section II., p. 24), the fowl-dung bate involves two fermentations,
in each of which (ærobic and anærobic) several species of bacteria
are probably active. Wood found the bacteria of the bate to be
chiefly cocci, and ascribed part of the difference in mechanism by
the nature of the media, which in the bate includes also the urinary
products. In the dog-dung puer, also, a lipolytic action is probably an
essential part of the total effect. The puer gives a much more
complete deliming and a much softer and more relaxed pelt than the
bate, it is therefore particularly suited to the needs of light leather
manufacture. The puering action has been imitated fairly
successfully by artificial methods. "Erodin" (Wood, Popp and Becker)
involves the use of B. erodiens and a suitable culture medium
including organic deliming salts: "Oropon," "Pancreol" and others
involve the use of ammonium chloride and trypsin, together with
some inert matter.
Light-leather goods are usually drenched after puering. They are
also often split green after the wet work. Sheepskins thus yield
"skivers" (the grain split), whilst the flesh split is often given an oil
tannage (see Part IV., Section III.). The greasy nature of sheep and
seal skins necessitates the processes of "degreasing." In the case of
sealskins this is done largely before liming, but with sheepskins
either after being struck through with tan, or after tannage is
complete. Sheepskins are often preserved in the pelt by pickling with
sulphuric acid and salt, which process forms a temporary leather.
The fibres of the pelt are dried in a separate condition, but the
adsorption is easily reversible and the pelts may be "depickled" by
weak alkalies and afterwards given an ordinary vegetable tannage.
In the vegetable tannage of skins for light leathers, the same
theoretical considerations have force as in the heavy-leather section,
but the former has its own rather special requirements and aims.
Generally speaking, a softer and more flexible leather is required,
but these qualities must not be imparted by stuffing with grease as
in the currying of dressing leather, because a bright and grease-free
result is usually required. Hence it is important that a sweet mellow
tannage be given. The durability of the leather is also a primary
consideration for goods intended for bookbinding, upholstery, etc.,
and the tannage must be arranged to impart this quality and avoid
anything tending to cause the perishing of the fibre. Thus oak bark
is a popular tanning material, and sulphuric acid very definitely
avoided. The tannage must be fast, and take the dyestuffs well, and
for the production of light shades of colour in dyeing must be a light-
coloured tannage. All these qualities are imparted by sumach, which
also fits in excellently with the other general requirements, such as
softness, brightness and durability. Hence sumach is the principal
light-leather tanning material, but the tendency is to employ other
materials—oak bark, myrabs, and chestnut extract—to do much of
the intermediate tanning, so that the expensive and useful sumach
may be used for setting the colour and grain at the commencement,
and for brightening, bleaching and mordanting the leather at the
end of the tanning process. Weight is generally no consideration, but
area is often a definite aim, partly because some goods are sold by
area and partly because the striking out, setting out and similar
operations improve the quality of the leather by giving evenness of
finish. Leather well struck out, moreover, is less liable to go out of
shape. As the grain pattern is so important in the finished leather,
appropriate care must be taken during tannage. If a smooth or a
fine grain finish is wanted, for example, the goods must not be
allowed to get wrinkled, creased, doubled or unduly bent to and fro
during the tanning. For such goods, suspension, careful handling
and even the "bag tannage" may be desirable, whilst for coarser and
larger grains paddles or drums may be more extensively used.
Amongst the finishing processes dyeing holds an important position.
The nature of the process has many points of similarity with that of
tanning. The great specific surface of pelt is probably more
enhanced than otherwise during tannage, at any rate with light
leathers, owing to the isolation of fibres, and consequently leather is
as liable as pelt to exhibit adsorption. The dyestuffs, on the other
hand, are substances very easily adsorbed. Some (like eosin and
methylene blue) are crystalloids, some (like fuchsin and methyl
violet) are semi-colloids, whilst others (like Congo red and night
blue) are undoubted colloids forming sols (usually emulsoid) with
water as dispersion medium. The crystalloids and semi-colloids may
also be obtained in colloidal solution, sometimes being so changed
on the mere addition of salts to the solution. In addition, the pelt
has been mordanted with tannin. If, however, leather has been kept
long in the rough-tanned or "crust" state, this may not be so
effective, owing probably to the secondary changes in tanning (Part
I., Section III., p. 46), but such leathers are usually "retanned" or
prepared for dyeing by sumaching (which process also incidentally
bleaches). The tannin mordant assists materially in the fixation of
the dyes. In the case of basic dyestuffs, lakes also are formed, i.e.
there is a mutual precipitation of oppositely charged colloids (+dye,-
tannin). The dyeing of leather is thus a case of colloid reactions even
more complicated than that of tanning.
Another finishing operation typical of the light leathers is "graining"
or "boarding." In this the skins after dyeing and drying are worked
by a board which is covered by cork, rubber, perforated tin or other
material, and so grips or "bites" the leather. The object of "graining"
is to work up the grain pattern by pushing or pulling a fold on the
skin with the board. The nature of the grain varies with the thickness
and the hardness of the skin, with the amount of pressure applied,
with the nature of the board, with the direction of the boarding and
with the total number of directions boarded. There is thus infinite
scope for variety of finish, and hence arise bold grain, fine grain,
hard grain, straight grain, cross grain, long grain, etc. The operation
requires considerable skill and experience. In the case of skins with
little natural grain (such as sheepskin) embossing and printing
machines impress the desired pattern.
In seasoning, a dressing is applied containing essentially albumins
and emulsified fats, e.g. egg albumin and milk. Colouring matters
are also often added to intensify or modify the shade. After
seasoning the goods are usually "glazed" by a machine which rubs
the seasoned grain with considerable pressure, by a glass or
hardwood tool, and so produces a high gloss, for which the
seasoning is very largely a preparation. Light leathers are very lightly
oiled with linseed or mineral oil.

REFERENCES.

Procter, "Principles of Leather Manufacture," pp. 220, 394.


Bennett, "Manufacture of Leather," pp. 36-41, 55, 85-90, 92-112,
312, 332.
Wood, "Puering, Bating and Drenching of Skins."
Lamb, "Leather Dyeing and Finishing."

SECTION II.—GOATSKINS

Goatskins are amongst the most valued raw material for the
manufacture of light leather. The leather obtained from them is of
the very finest quality in respect to durability and adaptability to the
principal purposes in view. The texture of the fibres in goatskin is
exceedingly compact and very strong, whilst the grain exhibits
naturally a characteristic pattern which renders it most suitable for a
grained finish. Hence for purposes like upholstery, bookbinding,
slippers, it forms almost an ideal material. The tanning and finishing
of goatskins into "morocco leather" may indeed be taken as a quite
typical example of light leather manufacture.
The skins are obtained from all quarters of the globe where goats
exist, and the excellent quality of the leather produced has created a
demand which is greater than the supply. This is due not only to the
demand for morocco leather, but also to the popularity of the
goatskin chrome upper leathers such as "glacé kid" (see Part III.,
Section IV.). The large American trade in the latter has produced the
saying that wherever there is a goat there is an American waiting for
it to die! The European supply of skins is somewhat limited. They
are obtained from the Balkans and Bavaria, in which case they are
small, fine-grained and plump skins. The Swiss goatskins are larger,
and have also a fine grain; they are well grown and well flayed.
Scandinavian skins have a poor reputation, being very flat. The
African supply is important; Abyssinian skins are exceedingly
compact and tough, and are very suitable for "bold grain" finishes.
The Cape skins are particularly large, strong and thick, but their
quality is often impaired by the cure, the skins being flint-dry, and,
like hides so cured, prone to unsoundness. Large quantities of
goatskins also come from the East. Many of these are imported in a
tanned state (E.I. Goat). These skins are tanned with turwar bark,
which contains a catechol tannin. They are also heavily oiled with
sesame oil, and need degreasing. The tannage is also stripped as far
as practicable, and the skins retanned with sumach before finishing.
They make good morocco leathers for many purposes, but the
primary catechol tannage renders them ineligible for finishing under
the specifications of the Committee of the Society of Arts. The skins
have a Persian or Indian origin. India also supplies a large number of
raw dried goatskins which are small and of variable quality. These,
however, are more extensively used for chrome uppers.
Goatskins are imported in either a salted or a dried condition. The
great aim of soaking is to obtain the skins in a thoroughly soft
condition. Hence the soaking is prolonged, and some mechanical
treatment is desirable in addition to various steepings in water. To be
certain of softness it is desirable to avoid the use of alkalies in the
soak waters, for although they cause hydration of the fibres by
imbibition, they also have a plumping effect which is not wanted at
this stage. Salted goatskins are first immersed in water and left until
the following day. This dissolves the salt. They are then stretched
and given a fresh soak liquor of water only to soften further, clean,
and remove the rest of the salt. This second water lasts only a few
hours, and the goods are then drummed well in running water. This
not only cleans quickly, but has an excellent softening effect. They
are again returned to a soak liquor, then softened mechanically by
working them over a beam. This treatment must be repeated,
drumming again if necessary, until the skins are perfectly relaxed
and thoroughly softened. If the treatment be very prolonged it
becomes advisable to use antiseptics in the soak waters after the
first drumming. Solubilized (or emulsified) cresols of the "Jeyes fluid"
type are the most suitable antiseptics, but too much must not be
used or the sterilization affects the liming, in which bacterial action is
needed. Flint-dry skins are left longer in the first soak, which should
be of water only. They are then given a fresh soak liquor containing
0.2 per cent. of sodium sulphide. Sometimes a 1.0 per cent. solution
of borax is used instead; it softens excellently, is antiseptic, and
avoids the plumping effect, but is rather expensive. The goods are
next drummed well, and resoaked and worked as for salted skins. In
either case the soaking takes about a week.
The liming of goatskins presents some points of contrast with the
methods used for other skins. These differences are due to the
exceedingly tight and compact nature of the skin fibres. This
compactness of texture makes it quite necessary to dissolve the
interfibrillar substance to a greater extent than usual, and also to
plump the fibres and split them into the constituent fibrils. These
effects are essential to obtain a rapid and complete tannage and a
soft leather. Too much bacterial action should be avoided, however,
or the brightness and soundness of the grain may be impaired,
which would be a fatal defect in such a leather. Hence the liming is
long rather than mellow, and sharp limes rather similar to those
required for sole leather are often used. Another result of the tight
texture of goatskin is that depilation is not easily effected. This
feature is rather intensified by the deepness of the hair-root. Hence
it is usual to employ sulphides to assist the depilation. In one
method two rounds of five pits are used. The skins are given about
two days in each pit, so that the liming lasts approximately three
weeks. In the first round, which consists of rather mellow limes,
arsenic sulphide is used to assist depilation. Up to 6 per cent. on the
weight of lime is added during slaking. This is a comparatively large
amount of arsenic sulphide, and the depilation is considerably
hastened; the skins indeed are unhaired after passing through this
round, i.e. after about 10 days' liming. In the next round the object
is plumping, and caustic soda (or carbonate) is added to the lime
liquors in quantities comparable to those suggested for sole leather
(Part I., Section V., pp. 55, 56). In this round the goods stay also for
about 10 days. An alternative to the above process is to hasten the
earlier part of the liming by employing sodium sulphide instead of
realgar. More sulphydrate may be obtained in solution in this way,
and the unhairing may be in about half the time. The sulphide of
soda also commences the plumping action which follows in the next
round, but this alternative has the disadvantage that the skins are
unhaired whilst the pelt is swollen with sulphide, which renders the
grain both harsh and tender and consequently more liable to
damage by the unhairer's knife.
Deliming is by puering and drenching, and is often associated with a
further mechanical working of the goods. The skins are inserted into
a puer liquor at 85° F. and thoroughly pulled down. The caustic
alkalies should be completely neutralized. A slight cut into a thick
part at the butt end should develop no pink colour with
phenolphthalein. The skins should be thoroughly relaxed, and the
swelling so much eliminated that they are quite soft, weak and
"fallen." The resilience and elasticity of the plumped skins should
have quite disappeared, and the impressions of hand or thumb
should be readily retained by the pelt. The grain should appear white
and possess a soft and silky feel. In this condition they are again
worked over the beam to soften further if possible. They are then
rinsed and again worked over the beam. Drenching follows with 10
per cent. of bran on the pelt weight, the operation commencing at
85° to 95° F., and lasting till next morning. The skins are next
scudded thoroughly to remove all dirt, but carefully so as not to
damage the grain.
In tanning, sumach and oak bark are the staple materials. Sumach
gives a much lighter colour, and hence it is used alone for goods that
are to be dyed the lighter shades, but oak bark is a "faster" tannage
and more preferable for dyeing in those cases where blacks and very
dark shades are wanted. For ordinary purposes a blend is usually
employed. A feature of oak bark, also, is that it tends to make a
firmer leather, so that the proportion used must be adjusted with
this fact in mind as well as the question of colour. For firmer
moroccos the skins may pass through a handler round of oak-bark
liquors (10°-20°) in which a certain amount of sumach is added to
the liquors. The sumach is leached and assists both in tanning and
bleaching as the liquor works through the round. The old liquor is
run to a paddle, and the tannage is commenced by paddling the
drenched skins in this liquor. It is advantageous both for the tannage
and for the efficient "spending" of the sumach if this liquor be
slightly warmed. In the early pit liquors the goods are very
frequently handled. There is, however, the usual tendency of the
times to save labour in this direction, and hence it is common to
have several paddles with liquors of gradually increasing strength,
followed by a shorter round of handlers in which the handling is
more infrequent. Instead of paddles latticed drums may be inserted
into pits containing liquors. These, however, are not quite so
convenient. In some tanneries, especially where sumach only is
employed, the tannage is in paddles throughout. A new liquor is
made up with fresh sumach and is used repeatedly until exhausted.
A three-paddle system sometimes obtains, in which case the
operation closely resembles the three-pit system of liming (Part I.,
Section II., p. 19), and the skins pass through an "old" liquor, a
"medium" liquor and a "fresh" liquor. The goods need not be paddled
the whole day through, and indeed in the later stages this is
undesirable. The packs remain several days in each liquor and take
up to 14 days to tan. Two to three bags of sumach are needed for
about 20 dozen goatskins. This method of tanning is efficient and
convenient for bold-grain finishes, on account of the constant
tumbling and bending of the skins which tends to work up a grain.
For very soft leathers and fine-grain finishes, however, the "bag-
tannage" or "bottle tannage" is favoured. In this method the pelt is
stitched up by machine to form a bag, grain outwards, leaving a
"neck" in the hind shank. The bag is nearly filled with a fairly strong
infusion of sumach, inflated with air and tied up at the neck. The
bags are then placed into a vat of warm sumach liquor, in which they
just float. The bags are pushed down and the liquor stirred up, so
that the goods are in constant motion. After a few hours they are
piled on a rack, and the tan liquor of the interior is caused to diffuse
through the skins by the pressure due to the weight of the pile. The
bags are refilled with fresh and stronger sumach liquor and the
process is repeated. The skins are thus lightly but effectively tanned
in about 24 hours, and the leather has very fine grain and soft feel.
However tanned the skins are dried out after tanning, and sorted in
the "crust" according to size and colour. The larger skins are
preferred for upholstery and the smaller for fancy goods and
bookbinding.
To illustrate the course of finishing operations, the case of hard-grain
morocco for bookbinding may be given as typical. The goods are wet
back with warm water and drummed for 1-2 hours in warm sumac
to prepare for dyeing. They are then struck out by machine,
sammed and shaved. Dyeing follows, with acid colours, in a drum.
The goods are run first in a little water and the dyestuff added very
gradually through a hollow axle. The acid required (preferably
formic) is added later to develop the full shade. Warm solutions are
used, and the dye bath is practically exhausted. The goods are next
placed in cold water to wash off superfluous liquor and free the skins
from acid. They are then horsed to drain, struck out and hung up to
samm. They are seasoned with milk and water and piled to temper.
They are "tooth rolled" in the glazing machine two ways: right-hand
shank to left fore shank and vice versâ, and piled again. After
wetting back again they are "wet grained" by hand with a cork board
in four directions: belly to belly, shank to shank, and across as
before, and finally from neck to butt. They are immediately hung up
in a warm shed to dry, and to fix the grain. They are then softened
by "breaking down" with a rubber board, top seasoned, piled to
temper and dry, brushed lightly, piled again, brushed more heavily,
and dried out. They are finally softened by graining in three
directions: shank to shank and across, and neck to butt. They are
then brushed again. If these skins are wanted for upholstery they
are shaved after dyeing, and nailed on boards to samm. They are
also dried out in a cooler shed or "stove," to ensure softness.

REFERENCE.

Bennett, "Manufacture of Leather," pp. 39, 55, 89, 111, 204, 344,
396.

SECTION III.—SEALSKINS

A special class of morocco leather is manufactured from the skins of


seals. This should not be confused with the "sealskin" of popular
parlance, which is manufactured from the skin of a different animal.
All the fin-footed mammals (Pinnipedia), except the walrus, are
termed seals, but they are divided into two families. The Otariidæ
are known by their possession of small but distinct external ears:
into this class fall the fur-seals whose skin is dressed with the fur on,
for women's jackets, muffs and caps. The Phocidæ are that family
without external ears: the skins of many species (Phoce
Greenlandica, Phoco barbata, etc.) of this family are unhaired and
given a vegetable tannage, thus forming the raw material of sealskin
morocco leather. It is with the latter that this section will deal.
As the seal is a marine animal and is partial to the colder seas, its
skin is very oily. The skins are imported in a salted condition from
both the Arctic and Antarctic regions. North Europe, North America
and Newfoundland supply many skins, and the southern material is
supplied chiefly through the Cape. Sealskin shares with goatskin the
properties of compact texture, strength of fibre, and great durability,
all of which fit it for the manufacture of moroccos for upholstery,
bookbinding, etc. It is, however, readily distinguishable from
goatskin by its characteristic grain pattern.
In soaking sealskins the object is not only to soften thoroughly, but
also to effect the recovery of as much seal oil as possible before the
liming commences. This is desired because the oil is in itself a
valuable bye-product, and because its removal is essential to a
satisfactory liming and tannage. The removal of the oil is materially
assisted by raising its temperature, so that the soaking of sealskins
is often done with warm water (85°-88° F.), after which treatment
they are laid over the beam and scraped with a blunt knife on both
flesh and grain. The oil flows away into a special receptacle. This
treatment is repeated until the bulk of loose oil is removed. The
process is known as "blubbering" or "brushing over." After some
soaking the skins are drummed to ensure softness. The skins are
then fleshed. More oil may be obtained from the fleshings.
By fleshing before liming a more regular action of the lime is
obtained. This is necessary to "kill" the grease still remaining in the
skin. A long and mellow liming is given for the same reason. Fully
three weeks are given, and old limes are much preferred, partly to
obtain the maximum lipolytic action and partly to avoid the intense
ribbing of the pelt which new limes so easily impart to the older
animals. These ribs are very difficult to eliminate in the subsequent
work. Some factories find it necessary to finish up in new limes,
however, in order to plump and split the compact fibre bundles into
their component fibrils. The plumped pelt is also easier to split
green. No sulphides are usually employed. Sweating (see Section IV.,
p. 113) is sometimes used for depilation, and in this case the ribbing
of the pelt does not take place.
The puering is unusually thorough with sealskins. This is to obtain
the maximum softness and take full advantage of the lipolytic action.
The puer liquor is fully 95° F., and the skins are paddled for about
three hours, or until fully pulled down and completely delimed.
Scudding follows, now usually by machine. The skins are then well
drenched. The action is intensified by the use of peameal in addition
to the bran. About 10 per cent. of the mixture on the weight of pelt
is used. It is customary, however, to drench at a lower temperature
(68°-70°) than in the case of goatskins (Section II., p. 102), but the
goods are left in the drench overnight only, as is usual in drenching.
It is quite possible that drenches worked differently may have also a
somewhat different fermentation and be due to other organisms
than the symbiotic bacteria discovered by Wood. It is equally
possible that the acids produced are also different, in relative
proportion, if not in nature, and that consequently there is a real
difference in the practical effect. In the Author's opinion, the great
probability is that in the drench are several fermentations, and that if
the action be reduced by lowering the temperature, but intensified
by adding peameal to the bran, some of these fermentations are
encouraged at the expense of others.
The tannage of sealskins depends upon the size of the skins, the
purpose for which they are intended, and whether they have been
split or not in the limed state. The largest and coarsest skins
intended for boot uppers, and those which have been heavily
scratched on the grain and are only suitable for enamels, are given a
tannage which may last about 5 weeks. The liquors are made from
oak bark and mimosa bark, and are made up to 35° with gambier
and possibly myrabolans extract. For fancy work also heavy skins are
used, but a softer tannage is needed. If for blacks the tannage is
with gambier and chestnut extract. Two sets of handlers are given
(10°-15° and 15°-20°), using only gambier in the green sets. They
are well sumached after tanning to bleach and to mordant. If for
colours, only sumach and oak bark are employed. The skins are first
paddled for 3-4 days in sumach liquors, in which they are coloured
through. The liquors may be warmed; this quickens the tannage and
also leaches the sumach. The skins are then split, and the grains
pass through a handler set with liquors made from oak bark
(8°-24°). The skins are in this set for 3 weeks, in the first half of
which they are very frequently handled. They are finished off by
paddling for 1 or 2 days in a fresh liquor containing much sumach,
which mordants the skins and bleaches the bark tannage. The flesh
splits are given a drum tannage in chestnut and quebracho extracts.
If small skins are being tanned for bookbinding purposes, sumach
only is employed, and usually the tannage is entirely in paddles.
In finishing many types of grain may be obtained, in blacks and in
colours. The finishing of "black levant" may, however, be selected as
a typical case. The skins are soaked back, tempered, and either split
or shaved, according to their substance and the size of grain
wanted. The thin skins of course give the fine grains. Mixed
tannages need scouring and possibly sumaching. The skins are then
oiled up with linseed oil, sammed, set out and blacked. In this last
operation the grain is brushed over with a solution of logwood and
ammonia, and afterwards with the iron mordant which often
contains glue. They are next hung up for a while and then "wet
grained" in four directions—belly to belly, shank to shank, across,
and neck to butt. After hanging up in a hot stove to set the grain,
they are cooled, fluffed on the flesh, and seasoned on the grain with
a solution of milk and blood. A little black dyestuff may be added to
the season. The season is well brushed in, the skins dried
somewhat, and then glazed. They are then grained four ways again
as above, dried out in the stove, and lightly oiled with warm linseed
oil on the grain.

REFERENCE.

Bennett, "Manufacture of Leather," 40, 56, 90, 112, 206, 251, 312,
346, 383.

SECTION IV.—SHEEPSKINS

The most numerous class of skins for light leathers is from the
common sheep. These skins have particular value inasmuch as they
include the wool as well as the pelt. This wool, which is actually the
most valuable part of the sheep's skin, is the raw material of our
woollen industries, and is one of the most important of animal
proteids. We have, therefore, in this section to consider this dual
value of sheepskins, the proteid of the epidermis (wool), and the
proteid of the dermis (pelt); one the raw material of the woollen
industry, the other the principal raw material of the light leather
trade. The first problem is to separate the two proteids. With other
skins and hides the ordinary liming processes were sufficient and
appropriate, but in the case of sheepskins the method is unsuitable,
because the exposure of the wool to the action of caustic lime and
possibly other alkalies would seriously impair its quality and reduce
its commercial value. Hence this separation of wool from pelt is
usually quite a separate business, viz. that of the "fellmonger,"
whose occupation it is to collect the sheepskins from butchers and
farmers, to separate the two important constituent proteids, and to
hand the wool in one direction to the "wool stapler," who sorts it
according to quality, and to hand the pelt in another direction to the
light leather tanner, who tans and finishes the pelt to fit it for light
upper work, fancy goods, etc.
In the first instance, therefore, we have to consider the work of the
fellmonger, the separation of wool and pelt. In this work the wool
receives first consideration, and the raw material of the fellmonger is
usually classified accordingly into "long wools," "short wools," and
"mountain breeds." The skins vary very largely in quality of wool and
in quality of pelt, being influenced very strongly by the conditions
under which the sheep lived, and by the precise breed of animal
from which the skin has been taken. As in the case of hides (Part I.,
Section I., p. 8), animals exposed to extremes of weather develop
the best pelts, whereas those sheep which have been carefully bred
and reared for the sake of their wool yield a thin and poor class of
pelt. In Britain, and more especially in England, are reared the finest
and most valuable sheep. This is evident from the prices paid for
them by foreigners and colonial breeders when seeking new blood
for their flocks and fresh stock for their lands. As much as 1000
guineas have been paid by an Argentine firm for a single Lincoln
ram.
Long wools are obtained from some of the best and most extensively
bred animals. The "Cotswolds" are the largest, and probably the
original breed of England are still found on the Cotswold Hills. They
have long wool, white fleeces, white faces, and white legs, and have
no horns. The wool is fine, but the pelts are particularly greasy,
especially along the back. A later breed originating in the Midlands
was called the "Leicester" long wool. This breed gives a great cut of
wool and much coarse mutton. It is very extensively distributed in
the North of England and has been much crossed, so that many sub-
breeds are now well known, e.g. the "Border Leicester"—the general
utility sheep of Scotland—and the "Yorkshire Leicester" or
"Mashams," much bred in Wensleydale. "Lincolns" are another long
wool found only on the Lincolnshire Wolds. They also have white
faces and shanks and yield a large pelt with fine grain. They give a
big crop of wool. "Devons" are a smaller breed common in
Somerset, Devon and Cornwall. They yield a fairly long wool of great
strength, but not quite white. Romney Marsh sheep ("Kents") are
also long wools. They have white legs, white faces, a tuft of wool on
the head, and no horns. The pelt is large and good. "Roscommons"
are an Irish cross-breed with much Leicester blood. They yield a
long wool and a spready pelt.
Short wools are typified by the "Down" sheep. These sheep are
extensively bred on the chalk lands which comprise a very large
percentage of the southern counties of England. The "South Downs"
are the best and most important, the breed being the general utility
sheep of England. They are small but well-shaped animals with grey
faces, no horns and fine close wool. The pelt is only fair, but the
mutton is excellent and provides the meat sold in our best shops.
This breed has largely stocked New Zealand. The "South Down" is a
somewhat delicate animal, and has therefore been largely crossed
with Cotswolds and other breeds. Many well-known cross-breeds are
found in the eastern and southern counties. The "Suffolks," for
example, are found in the eastern counties. They have black heads,
faces and legs. "Oxfords" and "Hampshires" are similar, but larger.
"Shropshires" are another hardy cross-breed, which yield a heavier
fleece. All the cross-breeds are larger than the South Down and yield
bigger pelts.
Mountain breeds yield wool of varying quality but give the best pelts.
The "Cheviots"—much favoured by the Scotch farmers—have a wool
of medium length but with much hair in it. They have white faces
and legs and no horns, and yield excellent pelts. The "Black-faced
Mountain Sheep" have longer wool but coarse, and yield good pelts.
They are kept in the hilly parts of North England and in the Scottish
Highlands. "Lonks" yield a large and good pelt, but very coarse wool.
The mutton is good. They are a very large breed with much curved
horns and black faces. There are also some small breeds, "soft
wools," "Shetlands," and "Welsh Mountain Sheep." The wool of the
last two is poor, but the Welsh pelts are valued for their fine grain.
There are large numbers of sheepskins also imported, from South
and Central America, and from Australia, New Zealand and the Cape.
The colonies, however, have often done their own fellmongering,
and we have imported pickled pelts. They now tan the skins also,
and many tanned sheepskins are now imported. There are also
many Indian skins imported after tannage with turwash bark (cp.
E.I. Goat, Section II., p. 100).
The depilation is brought about by "sweating" (or "staling") and by
"painting." The immediate object of both these types of method is to
avoid using any thing which will affect the wool. The sweating
process is the most ancient method of unhairing and is used in
America for hides as well as sheepskins. It consists of a more or less
regulated putrefaction. The loosening of hair or wool has long been
accepted as evidence that putrefaction had commenced in a hide or
skin, and it is the aim of the sweating process to stop the action at
that stage, before any damage has been done to the pelt. This aim
is achieved rather imperfectly by suspending the goods in closed
chambers and regulating the temperature and humidity by means of
steam and water. Such chambers are known as "sweat pits" or
"tainting stoves". In the case of sheepskins the "warm-sweat"
system is generally used, and the operation is carried out at 75°-80°
F. A satisfactory yield of wool is obtained in good condition, but the
pelt is very liable to suffer bacterial damage and show "weak grain."
The skins are first cleaned by a few "soaks" in clean fresh water,
with intermediate help from a "burring machine" which presents a
rapidly revolving set of spiral blades to the wool, and in the presence
of a good stream of water quickly removes all dirt from the wool.
The skins then enter the tainting stove, and the operation is
commenced by a slight injection of live steam. In summer, about a
week is sufficient to loosen the hair, but in winter up to two weeks
may be necessary. Little control of the process is possible, and all
that can be done is to watch the goods carefully near the end of the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like