How to open all the tables within a namespace in your console

When examining new data or monitoring a set of tables, you may want to show all of the tables in a namespace in your console. The following snippet shows all of the tables for the DbInternal namespace, using variable names equal to the table name.

ns="DbInternal"
db.getTableNames(ns).sort().each{
      publishVariable(it, db.liveTable(ns, it).where("Date=today()"))
}
ns = "DbInternal"
for tn in db.table_names(ns):
    globals()[tn] = db.live_table(ns, tn).where("Date=today()")

We will unpack the Groovy syntax below and explain how you can modify this script to work with your data.

SyntaxExplanation
ns="DbInternal";Sets the variable named "ns" to the value "DbInternal" (the namespace)
db.getTableNames(ns)Gets the list of table names in that namespace
.sort()Sorts the String names, using the default order (ascending) so that the variables are defined in a predictable order. New tabs in the console are created in that order.
.each{For each of the string names, this executes the following Groovy closure, which we define inline. The closure is executed once for each name in our list.
publishVariable (it,Creates a variable with the string contained in "it", which represents table name. For example, "AuditEventLog" is the name of one of the tables in the DbInternal namespace, so one of the created variables will be named "AuditEventLog".
db.i(ns, it)The second argument to publishVariable is the value to publish db.i(ns, it). This fetches an intraday table. To fetch historical tables, use db.t.
.where("Date=currentDateNy()")This filters your data to the current day. This .where filter is intended for Deephaven tables that use "Date" as a partitioning column and are centered around the date in New York. If your data is partitioned differently, or uses a different time zone, you should use a different filter. All the tables in the namespace must include this column.
)Close the publishVariable parentheses.
)}The end of the closure each began

The entire command can be written in one line by adding a semi-colon and removing line breaks:

ns="DbInternal";db.getTableNames(ns).sort().each{publishVariable(it, db.i(ns, it).where("Date=currentDateNy()"))}