'How do I return a list of all column titles in a table in SQLite? [duplicate]

I have a 20-or-so column table 'Contacts' in a Contacts.sqlite file. I use the Mac Terminal to interact with it, and am writing a program that will perform certain actions based on the number of columns in the table, as well as the name of each column.

Thus, I need to perform some sort of query that will return a list of all my column titles.

I have found various recommendations that look like some version of this:

SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'Schema' AND table_name = 'Table_Name'

but it almost always returns an error saying there is "no such table: information_scheme.columns".



Solution 1:[1]

Looks like SQLite does not support information_schema. You can retrieve the list of table names from sqlite_master. But there is no table with columns.

Instead, SQLite supports the proprietary pragma table_info():

pragma table_info(table_name);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1