sql生成唯一的表/视图名称 [英] sql generate unique table/view name

查看:118
本文介绍了sql生成唯一的表/视图名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一些疯狂的健壮代码。我想将查询作为字符串,创建一个临时视图/表来存储结果,使用它,然后删除表。我想使用一个数据库中肯定不存在的名称。是否有SQL命令生成唯一的表名?如果这是特定于实现的,我将使用postgresql。

I want to create some mad robust code. I want to take a query as a string, create a temporary view / table to store the results, use it, then drop the table. I want to use a name that is guaranteed to not already exist in the database. Is there an SQL command to generate a unique table name? I'm using postgresql if this is implementation-specific.

推荐答案

您可以使用临时表。临时表对其他连接不可见。如果存在与临时表同名的永久表,则该永久表对当前连接不可见。

You could use a temporary table. Temporary tables are invisible to other connections. If a permanent table with the same name as the temporary table exists, the permanent table is invisible to the current connection.

CREATE TEMPORARY TABLE table_name  
(  
 column_name1 data_type(length) constraints,  
 column_name2 data_type(length) constraints,  
 ...

请参见PostgreSQL 手册页

See the PostgreSQL manual page.

这篇关于sql生成唯一的表/视图名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆