Postgresql:如何创建表,如果它不存在? [英] Postgresql: how to create table only if it does not already exist?

查看:731
本文介绍了Postgresql:如何创建表,如果它不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Postgresql中,如果创建表不存在,我该如何做一个条件?

In Postgresql, how can I do a condition to create a table only if it does not already exist?

感谢代码示例。

推荐答案

我不知道它何时被添加,但为了完整起见,我想指出,版本9.1(可能之前)如果不存在可以使用。 如果NOT EXISTS 只创建表格,如果它不存在。

I'm not sure when it was added, but for the sake of completeness I'd like to point out that in version 9.1 (maybe before) IF NOT EXISTS can be used. IF NOT EXISTS will only create the table if it doesn't exist already.

示例:

CREATE TABLE IF NOT EXISTS users.vip
(
  id integer
)

这将在架构中创建一个名为 vip 的表<$ c $

This will create a table named vip in the schema users if the table doesn't exist.

来源

这篇关于Postgresql:如何创建表,如果它不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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