How to check whether a table exist


#1

res = c.execute('SELECT * from "f4659b40-03a8-4b6e-ab47-e0c46fdab44f" LIMIT 1')
print(res.fetchall())```

its giving me error as object not found
but if i give query as it giving output
res = c.execute("SELECT * from snidata LIMIT 1")

can you help how to check whether this table "f4659b40-03a8-4b6e-ab47-e0c46fdab44f" exist in mapd 
database to connect to mapad database i am using above link

i also want to know how to describe a table using query

#2

Hi @nagulan,

I confirmed that the table " f4659b4-…" does not exist:

table_name = “f4659b40-03a8-4b6e-ab47-e0c46fdab44f”
connect_to_mapd(db_login, db_password, mapd_host, database)
print(connection.get_table_details(table_name))
mapd.ttypes.TMapDException: TMapDException(error_msg=“Table f4659b40-03a8-4b6e-ab47-e0c46fdab44f doesn’t exist”)

But when I change the table_name to “snidata” then I am able to access the table definition:
Connection(mapd://mapd:***@deepbox.thickdata.io:9091/mapd?protocol=binary)
[ColumnDetails(name=‘f_ord_dcsn_rid’, type=‘DECIMAL’, nullable=True, precision=10, scale=0, comp_param=0), ColumnDetails(name=‘acp_dcsn_ct’, type=‘DECIMAL’, nullable=True, precision=10, scale=0, comp_param=0), ColumnDetails(name=‘dcsn_ct’, …

The problem is most likely the “-” in the name of the table, try creating without it.
Regards,
Veda


#3

Hi @nagulan,

I confirmed that the table creation will fail if the name has a hyphen “-”, substitute it with underscore “_” and it will work.

Regards,
Veda


#4

@veda
ok thankyou for your time


#5

@veda
how to query to check list of tables in database