0

If I attempt to create a table like:

r.tableCreate("mytable").optArg("primary_key", "id").run(conn);

It will throw an exception if mytable already exists.

My question is simple: is there a more appropriate procedure to determine whether a table already exists other than try/catch the exception? E.g. a method returning a boolean value or a method that creates only if not exists.

Thank you for your attention

edit: regarding this answer, the methods r.dbList() and r.tableList() did not return any information regarding the tables. In line with this, the methods r.tableList().contains() and r.dbList().contains() do not return an answer to my question. Note that I am using the following Java lib:

<dependency>
  <groupId>com.rethinkdb</groupId>
  <artifactId>rethinkdb-driver</artifactId>
  <version>2.3.3</version>
</dependency>

and I am not sure if the above-mentioned methods from this library are meant to be equivalent to those mentioned in this answer.

João Matos
  • 6,102
  • 5
  • 41
  • 76
  • is this from a specific library/framework? – Stultuske Sep 17 '18 at 13:12
  • not sure if I understood the question, I imported rethinkdb-driver (com.rethinkdb) as a maven dependency. – João Matos Sep 17 '18 at 13:14
  • so basically this is a question about rethinkdb? have you checked it's documentation? – Stultuske Sep 17 '18 at 13:15
  • I think this is exactly what you are looking for: https://stackoverflow.com/questions/31625913/in-rethinkdb-what-is-the-easiest-way-to-check-if-a-database-or-a-table-exists – Stultuske Sep 17 '18 at 13:16
  • yes, I found no answer to my specific question – João Matos Sep 17 '18 at 13:16
  • Check the link I commented – Stultuske Sep 17 '18 at 13:17
  • Possible duplicate of [In RethinkDB, what is the easiest way to check if a database or a table exists?](https://stackoverflow.com/questions/31625913/in-rethinkdb-what-is-the-easiest-way-to-check-if-a-database-or-a-table-exists) – Leviand Sep 17 '18 at 13:18
  • yes I had already seen that answer, unfortunately the method r.dbList().contains('example_database') and the method r.tableList().contains('example_database'), do not have the expected outpt – João Matos Sep 17 '18 at 13:19
  • not sure if this is relevant or not but that answer is not for java, maybe a limitation of the rethinkdb java lib ? – João Matos Sep 17 '18 at 13:21
  • _r.tableList() did not return any information regarding the tables_ this seems hardly conceivable... What was the information returned? _and the method r.tableList().contains('example_database'), do not have the expected outpt_ then what are you expecting and what did you get instead? (Hoping trying a _table_ named _example_database_ was a typo.) – Stock Overflaw Sep 26 '18 at 22:32

0 Answers0