0

I have a new table, with these columns (all NOT NULL):

creation_date, created_by, attribute_1, attribute_2, geometry

I also have an old table:

attribute_1, attribute_2, geometry

I want to insert the data from the old table through INSERT INTO / SELECT / FROM. However this obviously gives me an error for the creation_date and created_by columns because the old table does not have any. How do I insert a default value for these colmuns while inserting the rows from the old table?

MapEngine
  • 553
  • 1
  • 9
  • 21

2 Answers2

1

You should simply choose some literals. Unless that data exists elsewhere and you can look it up with a join, I would suggest something like:

INSERT INTO newtable
SELECT date('now') as creation_date, 
'Legacy Data' as created_by, attribute_1, attribute_2, geometry
FROM oldtable
Greg Viers
  • 3,473
  • 3
  • 18
  • 36
1

While creating the new table set the two new attributes as default attributes

CREATE TABLE NEWTABLE (COLUMN1 int default(X) NOT NULL, COLUMN2 int default(Y) NOTNULL, COLUMN3 int, COLUMN4 int) Here X and Y are values that will be provided to the columns if any INSERT happens, they can be updated afterwards. For COLUMN3 and 4 data can be inserted from any other table