Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

information_schema.columns on sqlite

I would like to do a query like next:

SELECT table_name, column_name, data_type, is_nullable, ... 
FROM information_schema.columns

on a sqlite database.

I checked

PRAGMA table_info(table_name); 

but doesn't suit my needs, just check fields for one table.

I checked

select * from sqlite_master where type = 'table';

But this just gets table names and creation query.

Is there any way to "join" these to methods? or any other suggestion or ideas? tx

like image 817
Jhonny D. Cano -Leftware- Avatar asked Apr 18 '09 14:04

Jhonny D. Cano -Leftware-


People also ask

Does SQLite have Information_schema?

There is no information_schema in SQLite as pointed out by @mustaccio. However, you can get the information you require by using this SQL: SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%'; See the link here.

How do I see all columns in SQLite?

Show all columns in a SQLite table. In TablePlus, you can either open the Query Editor and run the statements above, or see all columns from the GUI's table structure view: From the table data view, to switch to structure view, click on the Structure button at the bottom of the window, or press Command + Control + ].

How do I get a list of column names in SQLite?

PRAGMA table_info(table_name); will get you a list of all the column names.

How do I merge two columns in SQLite?

SQLite uses double-pipes ( || ) - more formally known as the concatenation operator - to combine strings. You can combine both literal strings (in quotation marks) and column values using this operator.


1 Answers

I know you don't want to hear this, but you're not going to be able to do the join from SQL with SQLite. The table_info pragma is not mapped to a standard query, but rather a virtual machine program hard-coded into the SQLite sources. That program only supports a single table. Full stop. :)

If your needs are just testing, it shouldn't be too hard to write script to do what you want. Otherwise, you're going have to write this into your application. Either way, you'll be select the table name from sqlite_master using your sqlite_master query, make a SQL query from it using sqlite3_mprintf("pragma table_info(%s);",name), and prepare/execute that.

like image 146
Steven Fisher Avatar answered Sep 22 '22 01:09

Steven Fisher