If[SQLExecute[con, "Select * from TABLE"] == "{}", Print["TRUE"], Print["FALSE"]]

I need to know the way, if the TABLE is empty or not

  • 5
    $\begingroup$ Why =="{}"? It's not going to return a string to you... It should be == {}. But retrieving all columns from all rows in the entire table (which could potentially be huge) is not a very good idea just to see if the table is empty, use SELECT COUNT(*) FROM table instead. $\endgroup$ – C. E. Sep 3 '14 at 6:36
  • $\begingroup$ Depending on your situation it may be better to run this in one pass and filter that list for further processing. E.g. in postgresql select schemaname, relname, n_live_tup from pg_stat_user_tables order by relname. $\endgroup$ – mfvonh Sep 3 '14 at 8:03

Here is one options:

If[SQLExecute[con, "Select * from TABLE","MaxRows" -> 1] == {},True, False]

If it's just a test, Using MaxRows you can prevent an unnecessary data load.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.