I followed a tutorial to create a PostgreSQL lookup table with the following schema:
CREATE TABLE public.link_categories
(
id integer NOT NULL DEFAULT nextval('link_categories_id_seq'::regclass),
name character varying(16) NOT NULL,
description text,
CONSTRAINT link_categories_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.link_categories
OWNER TO postgres;
As I understand it, the first field is a numerical "sequence" key that doesn't need to be populated; it just automatically fills with numerals as I add or delete rows.
I want to fill the second field with data from a spreadsheet, and I have nothing to put in the third field at the moment.
So I copied the one field I want to import into a new spreadsheet, then added a field on either side of it. So I have a three-column table with data in the center column only. I then saved it as a CSV file.
When I try to import it, I get the following error:
WARNING: null value in column "id" violates non-null constraint
How can I fill this table with data from one CSV file, using PostgreSQL 9.5 and pgAdmin III?
2 个答案:
答案 0 :(得分:1)
I assume you are using COPY?
You can specify the columns to insert. In this case, you would need to specify the three columns that are in the CSV (in the same order). Otherwise it will assume all columns.
答案 1 :(得分:0)
I see here, the guy is doing something similar, but using the serial data type. Maybe give that a shot.
Auto increment SQL function