Sai Wai Maung
Sai Wai Maung

Reputation: 1617

"null value in column ... violates not-null constraint" with INSERT INTO ... SELECT

I have two tables: the first table, customer_campaign_import, has 7 columns. The second table, customer_campaign, has more columns than the first table with id(uuid type) as the primary key. Since id is the type not-null constant , when I execute the following query:

INSERT INTO customer_campaign (store_name, store_address, store_city, store_province,     
 store_postal_code, lat, long)
SELECT * FROM customer_campaign_import;

It returns an error:

ERROR:  null value in column "id" violates not-null constraint

How do I generate a unique id for each row of the first table when inserting the first table into the second table?

Upvotes: 0

Views: 2866

Answers (1)

Sai Wai Maung
Sai Wai Maung

Reputation: 1617

ALTER the type of id to serial solved the problem.

Upvotes: 1

Related Questions