How to check the number of columns of a table in SQLite?

Hello Guys! I am wondering How can one check the number of columns of a table in SQLite when working in Jupyter locally?

I know that running the code below will show the number of rows:

FROM <table_name_here>;

What line of codes will work to get the number of columns?

And is it possible to check and get the number of rows and columns in a table at the same time, like we can do with pandas DataFrame by running just the code:

DataFrame.shape → returns number of rows and columns at the same time.

Thank you all for responses in advance!!!

Hi, below variant for postgres
Select required database and run (replace x to name of required table)
select count(*)
from information_schema.columns
where table_name=‘x’;

for vew name of column:
select column_name from information_schema.columns
where table_name=‘x’;

I just found a solution to this for SQLite.

FROM pragma_table_info('table_name');

Hope this helps

1 Like