PostgreSQL bulk loader
Description
The PostgreSQL bulk loader transform streams data from Hop to Postgresql using "COPY DATA FROM STDIN" into the database.
boolean stream fields are serialized as t or f, which PostgreSQL COPY accepts for boolean columns.
|
binary stream fields (for example a 16-byte hash key) are serialized as PostgreSQL bytea hex, \xdeadbeef.
|
the data is always sent in UTF-8 and the COPY command declares it with ENCODING 'UTF8', so the connection’s client_encoding does not matter. The server converts the text to the database encoding, and a character the database cannot store fails the load.
|
| the "Date" and "DateTime" date masks always write ISO dates with Gregorian years and ASCII digits, whatever the regional settings. "Pass through" writes the date in the stream field’s own format. |
| numbers read with lazy conversion are copied as they were read when PostgreSQL reads that text the same way: a plain format with a decimal point, no grouping symbol in the value, and an encoding that keeps ASCII digits as ASCII. Other values, for example with a decimal comma, are converted first. |
COPY error messages rarely name the stream field and value. Put Database value validation in front of this transform to catch over-long strings, encoding problems, numeric overflow and invalid UUID/JSON before COPY runs.
|
The PostgreSQL bulk loader is linked to the database type. It will fetch the JDBC driver from the hop/lib/jdbc folder. Valid locations for the JDBC driver for this transform are the database plugin lib and the main hop/lib folder. It will not work in combination with the SHARED_JDBC_FOLDER variable. |
Options
| Option | Description |
|---|---|
Transform name |
Name of the transform. |
Connection |
Name of the database connection on which the target table resides. |
Target schema |
The name of the Schema for the table to write data to. This is important for data sources that allow for table names with dots '.' in it. |
Target table |
Name of the target table. |
Load action |
Insert, Truncate. Insert inserts, truncate first truncates the table. |
DB Name Override |
(optional) database name to override the database name used in this transform’s connection. |
Enclosure |
the enclosure character to use in the |
Delimiter |
the delimiter character to use in the |
Stop on error |
Stop the execution of this transform when an error occurs |
Fields to load |
This table contains a list of fields to load data from, properties include:
|
Samples
The samples project has transforms/postgresql-bulk-loader.hpl, which empties the table public.hop_samples_bulk and loads the 2 rows of a Data grid, with the fields id and name, into it with COPY.
Create a connection named postgresql and the table with CREATE TABLE public.hop_samples_bulk (id INTEGER, name VARCHAR(50)) before you run it.