检查Tarantool中是否存在SQL表

时间:2019-07-16 15:01:13

标签: sql tarantool

如何检查Tarantool SQL是否已存在表?

1 个答案:

答案 0 :(得分:3)

仅使用SQL工具,可以通过以下方式完成:

SELECT EXISTS (select true from "_space" where "name" = 'table_name')

例如:

tarantool> SELECT EXISTS (select true from "_space" where "name" = 'T1')
---
- metadata:
  - name: EXISTS (select true from "_space" where "name" = 'T1')
    type: boolean
  rows:
  - [true]
...

tarantool> SELECT EXISTS (select true from "_space" where "name" = 'T')
---
- metadata:
  - name: EXISTS (select true from "_space" where "name" = 'T')
    type: boolean
  rows:
  - [false]
...

在Lua模式下:

tarantool> box.space.T1 ~= nil
---
- true
...

tarantool> box.space.T ~= nil
---
- false
...