SQL 选择到 PostgreSQL 中的临时表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29964708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:34:31  来源:igfitidea点击:

Select into temp table in PostgreSQL?

sqlpostgresql

提问by Parthasarathi

How to create temporary table using select into in PostgreSQL. For example in SQL Select * into temp_tab from source_tab;

如何在 PostgreSQL 中使用 select into 创建临时表。例如在 SQLSelect * into temp_tab from source_tab;

回答by Rahul Tripathi

You can try to use Create Table Ascommand like this:

您可以尝试使用Create Table As命令,如下所示:

CREATE TEMP TABLE mytable AS
SELECT * from source_tab;

From the docs:

从文档:

This command is functionally similar to SELECT INTO, but it is preferred since it is less likely to be confused with other uses of the SELECT INTO syntax. Furthermore, CREATE TABLE AS offers a superset of the functionality offered by SELECT INTO.

The CREATE TABLE AS command allows the user to explicitly specify whether OIDs should be included. If the presence of OIDs is not explicitly specified, the default_with_oids configuration variable is used.

此命令在功能上类似于 SELECT INTO,但它是首选,因为它不太可能与 SELECT INTO 语法的其他用途混淆。此外,CREATE TABLE AS 提供了 SELECT INTO 提供的功能的超集。

CREATE TABLE AS 命令允许用户明确指定是否应包含 OID。如果未明确指定 OID 的存在,则使用 default_with_oids 配置变量。