{"record":{"id":"176251076f193f13","repo":"stanfordnlp/CoreNLP","slug":"table-table-does-not-exist-in-the-database-run","errorCode":null,"errorMessage":"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);","messagePattern":"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\\);","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/GoogleNGramsSQLBacked.java","lineNumber":164,"sourceCode":"\n      isresult = stmt.getMoreResults();\n    } while (isresult);\n\n\n    assert(counts.size() == strs.size());\n    return counts;\n  }\n\n  //Adding google ngrams to the tables for the first time\n  public static void populateTablesInSQL(String dir, Collection<Integer> typesOfPhrases) throws SQLException{\n    connect();\n    Statement stmt = connection.createStatement();\n\n    for(Integer n: typesOfPhrases) {\n      String table = tablenamePrefix + n;\n\n      if(!existsTable(table))\n        throw new RuntimeException(\"Table \" + table + \" does not exist in the database! Run the following commands in the psql prompt:\" +\n          \"create table GoogleNgrams_<NGRAM> (phrase text primary key not null, count bigint not null); create index phrase_<NGRAM> on GoogleNgrams_<NGRAM>(phrase);\");\n\n      for(String line: IOUtils.readLines(new File(dir + \"/\" + n + \"gms/vocab_cs.gz\"), GZIPInputStream.class)){\n        String[] tok = line.split(\"\\t\");\n        String q = \"INSERT INTO \" + table + \" (phrase, count) VALUES (\" + escapeString(tok[0]) +\" , \" + tok[1]+\");\";\n        stmt.execute(q);\n      }\n    }\n  }\n\n  /** Note that this is really really slow for ngram > 1\n   * TODO: make this fast (if we had been using mysql we could have)\n   * **/\n  public static int getTotalCount(int ngram){\n    try{\n      connect();\n      Statement stmt = connection.createStatement();\n      String table = tablenamePrefix + ngram;","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/GoogleNGramsSQLBacked.java#L146-L182","documentation":"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.","triggerScenarios":"Calling populateTablesInSQL (or the main entry point of this class) against a database where the required GoogleNgrams_<n> tables or indexes were never created.","commonSituations":"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.","solutions":["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","Confirm the JDBC connection string points at the database/schema where the tables were created","Verify with \\dt in psql that the GoogleNgrams_* tables exist before running populateTablesInSQL"],"exampleFix":"// before (empty DB)\njava edu.stanford.nlp.util.GoogleNGramsSQLBacked ...\n// after (create tables first)\npsql -c \"create table GoogleNgrams_1 (phrase text primary key not null, count bigint not null); create index phrase_1 on GoogleNgrams_1(phrase);\"\njava edu.stanford.nlp.util.GoogleNGramsSQLBacked ...","handlingStrategy":"validation","validationCode":"ResultSet rs = stmt.executeQuery(\"select to_regclass('GoogleNgrams_1')\");\nif (!(rs.next() && rs.getObject(1) != null)) throw new IllegalStateException(\"Create GoogleNgrams tables before populating\");","typeGuard":null,"tryCatchPattern":"try { populateTablesInSQL(dir); } catch (RuntimeException e) { if (e.getMessage().contains(\"does not exist\")) { runDDL(); retry(); } else throw e; }","preventionTips":["Run the documented DDL for every n-gram size before population","Verify tables with \\dt in psql using the same DB/user the Java code connects with","Keep setup scripts in version control alongside the loader"],"tags":["postgresql","sql","database","missing-table"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}