I have two tables in two separate sqlite3 databases. The datatypes are identical, but the schemas slightly different. I want them to be a single table in a single database with the same schema as Table 2
Table 1
CREATE TABLE temp_entries (
id INTEGER PRIMARY KEY,
sensor NUMERIC,
temp NUMERIC,
date NUMERIC);
Table 2
CREATE TABLE "restInterface_temp_entry" (
"id" integer NOT NULL PRIMARY KEY,
"dateTime" integer NOT NULL,
"sensor" integer NOT NULL,
"temp" integer NOT NULL
);
id is not unique between the two tables. I would like to create another table with the same schema as Table 2. I would like the id for the entries in Table 1 to start from 0 and then the entries from table 2 to start after the last entry from table 1.
Ideally I would like to just add the entries from Table 1 to Table 2 and “reindex” the primary key so that it was in the same ascending order that “dateTime” is.
UPDATE: I now have both tables using the same schema, I did this by creating a new table with the same schema as Table 2 into the database that held Table 1. I than copied the data to the new table with something like:
INSERT INTO restInterface_temp_entry(id,dateTime,sensor,temp)
...> select id,date,sensor,temp FROM temp_entries;
Background
I used to record a bunch of temp_entries to a csv file. I wanted to put the data into a format that was easier to work with and chose sqlite3. I wrote a program that pulled all of the entries out and put them into Table 1. I wasn’t sure what I was doing at the time, and used Table 2 for all new entries. Now I want to combine them all, hopefully keeping id and date in ascending order.
Figured it out.
Attach to original database
Move records from current database to old database, leaving out the PK
Clear current databases table
Copy everything updated records from original databases table back to current.