We only handle single row INSERT statements. Insert statements with multiple rows are broken: we construct a row with all of the values in the multiple rows concatenated together.
Some history ...
In pgdump, the default way to write out data to the dump file is to use COPY-FROM. However, you can also get pgdump to generate INSERT statements. The very first version of harbourbridge used the insert version (it was kind of easier to start with). When pgdump generates INSERTS, it only generates them with one row at a time i.e.
INSERT INTO public.products (product_id, description, price, date_added) VALUES ('abc-123', 'Blue suede shoes', '141.99', '2020-06-06');
And so to get harbourbridge bootstrapped, that's all that was implemented. Then we switched to using COPY-FROM, and (mostly) stopped using INSERT.
However, PostgreSQL does support multi-row inserts i.e.:
INSERT INTO public.products (product_id, description, price, date_added) VALUES
('abc-123', 'Blue suede shoes', '141.99', '2020-06-06'),
('axd-673', 'Antique typewriter', '99.99', '2020-06-07'),
('zxi-631', 'Glass vase', '55.50', '2020-06-10');
These get completely mangled at the moment! The main issue is in getVals, which builds the following row for this multi-row INSERT:
vals = ["abc-123" "Blue suede shoes" "141.99" "2020-06-06" "axd-673" "Antique typewriter" "99.99" "2020-06-07" "zxi-631" "Glass vase" "55.50" "2020-06-10"]
i.e. all of the values from all of the rows concatenated together!
To fix this, we should:
a) return [][]string from getVals
b) change copyOrInsert to handle [][]string for vals (maybe we should call it rows?)
c) change ProcessPgDump to handle multi-row inserts i.e. iterate over the [][]string and call ProcessDataRow on each row.
d) add a test for multi-row INSERT statements (in fact, this should probably be the first step!)
Here's a complete dump file to test this out:
CREATE TABLE public.products (
product_id character varying(20) NOT NULL,
description character varying(1000),
price numeric(10,2),
date_added date
);
INSERT INTO public.products (product_id, description, price, date_added) VALUES
('abc-123', 'Blue suede shoes', '141.99', '2020-06-06'),
('axd-673', 'Antique typewriter', '99.99', '2020-06-07'),
('zxi-631', 'Glass vase', '55.50', '2020-06-10');