1

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".

user2352275
  • 11
  • 1
  • 2
  • Please don't use tags that don't apply to your question – John Conde May 05 '13 at 16:28
  • Hmm, I didn't believe I used irrelevant tags, but I will do my best. DCoder found a great article: the .schema command worked well. Andomar's solution worked well, also. Thanks so much! – user2352275 May 05 '13 at 17:00

1 Answers1

6

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);
Andomar
  • 232,371
  • 49
  • 380
  • 404
  • Hmm, I didn't believe I used irrelevant tags, but I will do my best. DCoder found a great article: the .schema command worked well. Andomar's solution worked well, also. Thanks so much! – user2352275 May 05 '13 at 16:47