code: private TableLoadResult export (Table table, String filterSql) {
          long startTime = System.currentTimeMillis();
          TableLoadResult tableLoadResult = new TableLoadResult();
          try {
              if (filterSql == null) {
                  throw new IllegalArgumentException("filterSql argument cannot be null");
              } else {
                  // Surround filter SQL in parentheses.
                  filterSql = String.format("(%s)", filterSql);
              }
  
              // Create entry for table
              String textFileName = table.name + ".txt";
              ZipEntry zipEntry = new ZipEntry(textFileName);
              zipOutputStream.putNextEntry(zipEntry);
  
              // don't let CSVWriter close the stream when it is garbage-collected
              OutputStream protectedOut = new FilterOutputStream(zipOutputStream);
              String copySql = String.format("copy %s to STDOUT DELIMITER ',' CSV HEADER", filterSql);
              LOG.info(copySql);
              // Our connection pool wraps the Connection objects, so we need to unwrap the Postgres connection interface.
              CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
              tableLoadResult.rowCount = (int) copyManager.copyOut(copySql, protectedOut);
              if (tableLoadResult.rowCount == 0) {
                  // If no rows were exported, keep track of table name for later removal.
                  emptyTableList.add(textFileName);
              }
              zipOutputStream.closeEntry();
              LOG.info("Copied {} {} in {} ms.", tableLoadResult.rowCount, table.name, System.currentTimeMillis() - startTime);
              connection.commit();
          } catch (SQLException | IOException | IllegalArgumentException e) {
              // Rollback connection so that fatal exception does not impact loading of other tables.
              try {
                  connection.rollback();
              } catch (SQLException ex) {
                  ex.printStackTrace();
              }
              tableLoadResult.fatalException = e.toString();
              LOG.error("Exception while exporting tables", e);
          }
          return tableLoadResult;
      }
docs: Export a table to the zipOutputStream to be written to the GTFS.