1
votes

I want to perform a data copy from one DB to another, but I want to do so only on tables contain a "unit_id" column.

I thought I can use the PRAGMA table_info(table_name) to help me with identifying whether or not the table "table_name" has the column "unit_id".

I read the documantation and realized I can check the "name" column. but without the documantation, how can one know the columns names returned from a PRAGMA usage?

Is there something like .schema "table name" that I can use on a PRAGMA result?

example:

PRAGMA table_info(units);

returns this:

0|id|INTEGER|1||1
1|unit_type_id|INTEGER|1||0
2|site_id|INTEGER|1||0
3|modbus_address|INTEGER|1||0
4|Name|TEXT|1||0
5|Description|TEXT|0||0
6|Needs_Download|INTEGER|1||0
7|needed_reset_apps|INTEGER|0||0

but how can i know which column is what?!

Thanks, Jim.

1

1 Answers

0
votes

Like a normal query, the data returned by PRAGMA table_info has column names:

sqlite> .header on
sqlite> pragma table_info(units);
cid|name|type|notnull|dflt_value|pk
0|id|INTEGER|0||1
1|unit_id|INTEGER|0||0
2|etc.|FLUFFY BUNNIES|0||0

The meaning of the columns is documented in the documentation.