Chapter 4. Loading Data
Before running queries or using analytic tools, Greenplum needs to ingest data. There are multiple ways to move data into Greenplum. In the sections that follow, we’ll explore each of them.
INSERT Statements
The simplest way of inserting data is to use INSERT SQL statement that facilitates inserting a few rows of data. However, because the insert is done via the master node of Greenplum Database, it cannot be parallelized.
An insert like the one that follows is fine for populating the values in a small lookup table.
INSERT INTO faa.d_cancellation_codes
VALUES ('A', 'Carrier'),
('B', 'Weather'),
('C', 'NAS'),
('D', 'Security'),
('', 'none');
There are set-based insert statements that can be parallelized. They are discussed later in this chapter.
\COPY command
The \COPY command is both a psql command as well as a SQL command in Greenplum, with minor differences, one of which is that COPY can be used only by gpadmin, the Greenplum superuser. You can run \COPY as psql scripts. psql is the command-line tool for accessing Greenplum as well as PostgreSQL. A Greenplum version is available as part of the normal installation process.
\COPY is efficient for loading smallish datasets—a few thousand rows or so—but because it is single-threaded through the master server, it is less useful for loads of millions of rows or more.
Let’s consider a table called dogs, defined as follows:
CREATE TABLE dogs (did int, dname text, bday date) distributed randomly;
Now, let’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access