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
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.
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 + ].
PRAGMA table_info(table_name); will get you a list of all the column names.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With