Nyxynyx
Nyxynyx

Reputation: 63599

PostgreSQL SequelizeDatabaseError: unrecognized configuration parameter "tables"

When running the following code using Sequelize 5.21.3 to get a list of all the tables in PostgreSQL 11.5 database:

sequelize.query('SHOW TABLES', {
        type: sequelize.QueryTypes.SHOWTABLES
    })
    .then(result => {
        console.log(result)
    })

we get the error:

Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"

What is the correct way to get a list of all the tables in the current PostgreSQL database using Sequelize?

Full Code

const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];

sequelize = new Sequelize(config.database, config.username, config.password, config);
sequelize.query('SHOW Tables', {
        type: sequelize.QueryTypes.SHOWTABLES
    })
    .then(result => {
        console.log(result)
    })

Full Error Stack

Executing (default): SHOW TABLES

Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"
    at Query.formatError (/Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)
    at /Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:72:18
    at tryCatcher (/Users/nyxynyx/test/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

config

{
  "development": {
    "username": "postgres",
    "password": "mypassword",
    "database": "database_development",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "operatorsAliases": "0",
    "define": {
      "timestamps": false
    }
  },
...

Upvotes: 1

Views: 5441

Answers (1)

GMB
GMB

Reputation: 222382

SHOW TABLES is MySQL syntax, that is not supported in Postgres.

If you are running psql, you can use the \dt command.

A more generic solution is to query system view information_schema.tables (which is available in more RDBMS):

select table_schema, table_name from information_schema.tables

You can also query pg_catalog.pg_tables, which is Postgres-specific.

Upvotes: 6

Related Questions