Ekaterina Mishina
Ekaterina Mishina

Reputation: 1723

SQLight 3: append table

I have a table1 with column attributes col1 col2 col3 which is filled with some data, say matrix A. I get new data with attributes col2 col3 col4 - they come in a form of a list with attribute names and a matrix B of data themselves.

I want to add the new data to the existing table1 to get the structure like this:

col1 col2 col3 col4
a11  a12  a13  -
     ...
aN1  aN2  aN3  -
-    b11  b12  b13
-         ...
-    bM1  bM2  bM3

Is there any easy way to do it? Maybe create a new temporary table first, append it somehow to the existing one and delete it?

Additionally, I want to be able to check for the new data if they have intersection by col2 with some existing data, e.g. if b11 is equal to any of ai2.

p.s. I use sqlite3 package from Python3 - don't know if it brings any limitation to SQLite functionality...

Upvotes: 0

Views: 212

Answers (1)

Infinite_Loop
Infinite_Loop

Reputation: 380

Have you tried the ALTER method?

example=sqlite3.connect('your_database_name.db')
cursor=example.cursor()
cursor.execute('ALTER TABLE your_table_name ADD COLUMN your_data TEXT')

or where it says "TEXT", you put whatever your data type is "REAL", "INT" Hope this helps

Upvotes: 1

Related Questions