1

We do have a function column_ifexists() which refers to a certain column if it exists, otherwise it refers to another option if we provide. Is there a similar function for table? I want to refer to a table and run some logic against it in the query , if the table exists , but if it doesn't exist, there shouldn't be a failure -- it should simply return no data.

e.g.

table_ifexists('sometable') | ...<logic>...
David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
Dhiraj
  • 3,396
  • 4
  • 41
  • 80

1 Answers1

0

Please note that the fields referenced in the query should be defined in the dummy table, otherwise in case of non-existing table, the query will yield an exception

Failed to resolve scalar expression named '...'

In the following example these fields are StartTime, EndTime & EventType

Table exists

let requested_table = "StormEvents";
let dummy_table = datatable (StartTime:datetime, EndTime:datetime, EventType:string)[];
union isfuzzy=true table(requested_table), dummy_table
| where EndTime - StartTime > 30d
| summarize count() by EventType
EventType count_
Drought 1635
Flood 20
Heat 14
Wildfire 4

Fiddle

Table does not exist

let requested_table = "StormEventsXXX";
let dummy_table = datatable (StartTime:datetime, EndTime:datetime, EventType:string)[];
union isfuzzy=true table(requested_table), dummy_table
| where EndTime - StartTime > 30d
| summarize count() by EventType
EventType count_

Fiddle

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88