stanfordnlp/CoreNLP · error · RuntimeException

Table does not exist in the database! Run the following…

Error message

Table ${table} does not exist in the database! Run the following commands in the psql prompt:create table GoogleNgrams_<NGRAM> (phrase text primary key not null, count bigint not null); create index phrase_<NGRAM> on GoogleNgrams_<NGRAM>(phrase);

What it means

GoogleNGramsSQLBacked.populateTablesInSQL loads Google N-gram vocabulary counts into a PostgreSQL database. Before inserting, it checks that the per-ngram table (e.g. GoogleNgrams_1) exists; if not, it throws this RuntimeException with the SQL DDL the user must run manually.

Solutions

  1. Run the DDL from the message in psql: create table GoogleNgrams_<NGRAM> (phrase text primary key not null, count bigint not null); create index phrase_<NGRAM> on GoogleNgrams_<NGRAM>(phrase); for each n you need
  2. Confirm the JDBC connection string points at the database/schema where the tables were created
  3. Verify with \dt in psql that the GoogleNgrams_* tables exist before running populateTablesInSQL

Example fix

// before (empty DB)
java edu.stanford.nlp.util.GoogleNGramsSQLBacked ...
// after (create tables first)
psql -c "create table GoogleNgrams_1 (phrase text primary key not null, count bigint not null); create index phrase_1 on GoogleNgrams_1(phrase);"
java edu.stanford.nlp.util.GoogleNGramsSQLBacked ...
Defensive patterns

Strategy: validation

Validate before calling

ResultSet rs = stmt.executeQuery("select to_regclass('GoogleNgrams_1')");
if (!(rs.next() && rs.getObject(1) != null)) throw new IllegalStateException("Create GoogleNgrams tables before populating");

Try / catch

try { populateTablesInSQL(dir); } catch (RuntimeException e) { if (e.getMessage().contains("does not exist")) { runDDL(); retry(); } else throw e; }

Prevention

When it happens

Trigger: Calling populateTablesInSQL (or the main entry point of this class) against a database where the required GoogleNgrams_<n> tables or indexes were never created.

Common situations: Setting up the Google N-grams resource on a fresh Postgres instance; pointing the code at the wrong database/schema; running as a user who cannot see the tables.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/176251076f193f13. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/GoogleNGramsSQLBacked.java:164

      isresult = stmt.getMoreResults();
    } while (isresult);


    assert(counts.size() == strs.size());
    return counts;
  }

  //Adding google ngrams to the tables for the first time
  public static void populateTablesInSQL(String dir, Collection<Integer> typesOfPhrases) throws SQLException{
    connect();
    Statement stmt = connection.createStatement();

    for(Integer n: typesOfPhrases) {
      String table = tablenamePrefix + n;

      if(!existsTable(table))
        throw new RuntimeException("Table " + table + " does not exist in the database! Run the following commands in the psql prompt:" +
          "create table GoogleNgrams_<NGRAM> (phrase text primary key not null, count bigint not null); create index phrase_<NGRAM> on GoogleNgrams_<NGRAM>(phrase);");

      for(String line: IOUtils.readLines(new File(dir + "/" + n + "gms/vocab_cs.gz"), GZIPInputStream.class)){
        String[] tok = line.split("\t");
        String q = "INSERT INTO " + table + " (phrase, count) VALUES (" + escapeString(tok[0]) +" , " + tok[1]+");";
        stmt.execute(q);
      }
    }
  }

  /** Note that this is really really slow for ngram > 1
   * TODO: make this fast (if we had been using mysql we could have)
   * **/
  public static int getTotalCount(int ngram){
    try{
      connect();
      Statement stmt = connection.createStatement();
      String table = tablenamePrefix + ngram;

View on GitHub (pinned to 1b7edd19c4)