dracoblue.net

SHOW TABLES in sqlite/postgresql

When working on craur's pdo functionalities, I wanted to know all tables in a specific pdo database.

If you are using mysql, you can use

SHOW TABLES;

to retrieve a list of all available tables in the current database.

But this does not work in postgres nor in sqlite.

In sqlite you can retrieve the table names with the following query:

SELECT name FROM sqlite_master WHERE type = 'table'

If you want to find all tables in a way, which works in postgresql and mysql, you can use the following query:

SELECT DISTINCT table_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'yourdatabasename'

The information_schema table has a lot more information (e.g. the column definitions etc.)

In postgresql, sqlite by
@ 05 Dec 2013, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About