检查Tarantool中是否存在SQL表

4

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

1个回答

4

只使用 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
...

nil进行比较只有在您明确想要布尔类型或想要特别表达检查存在意图时才是必要的。否则,您可以只需执行if box.space.T1 then print 'yes' else print 'no' endprint(box.space.T1 and 'yes' or 'no') :D - DarkWiiPlayer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接