简体   繁体   English

有条件地删除Redshift中的临时表

[英]Conditionally drop temporary table in Redshift

We are using http://aws.amazon.com/redshift/ and I am creating/dropping temporary tables in reports. 我们正在使用http://aws.amazon.com/redshift/ ,我在报告中创建/删除临时表。 Occasionally we encounter cases where someone has created a temporary table and failed to drop it. 偶尔我们会遇到有人创建临时表并且无法删除它的情况。

In other databases, for instance PostgreSQL which Redshift is based on, I could simply: 在其他数据库中,例如Redshift所基于的PostgreSQL,我可以简单地说:

DROP TEMP TABLE IF EXISTS tblfoo;

But that is a syntax error in Redshift. 但这是Redshift中的语法错误。 I can check for the existence of temporary tables myself using http://docs.aws.amazon.com/redshift/latest/dg/r_STV_TBL_PERM.html but that only works if I am a superuser and I am not running as a superuser. 我可以使用http://docs.aws.amazon.com/redshift/latest/dg/r_STV_TBL_PERM.html检查自己是否存在临时表,但这只有在我是超级用户并且我没有以超级用户身份运行时才有效。 I could also go and swallow exceptions, but with my reporting framework I'd prefer not to go there. 我也可以去吞下异常,但是在我的报告框架中,我宁愿不去那里。

So how can I, as a regular user and without generating database errors, conditionally drop a temporary table if it exists? 那么,作为普通用户,如果没有生成数据库错误,我如何有条件地删除临时表(如果存在)?

The test I ran showed that I could see other users' temp tables in stv_tbl_perm using a non-super user id. 我运行的测试显示我可以使用非超级用户ID在stv_tbl_perm中查看其他用户的临时表。 The cluster version I tested in is 1.0.797. 我测试的集群版本是1.0.797。 Note that no users can see other users' temp tables in pg_class. 请注意,没有用户可以在pg_class中看到其他用户的临时表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM