【问题标题】:How do I work with temporary table in postgresql with Azure Data Studio?如何使用 Azure Data Studio 在 postgresql 中处理临时表?
【发布时间】:2021-11-06 19:31:32
【问题描述】:

我在 Azure 中使用 Postgresql 数据库,但是当我使用临时表时,出现错误,指出不允许使用。

示例代码为:

select * into temptable from act_hi_taskinst

错误是:

SELECT ... INTO is not allowed here

我也按照链接https://www.postgresqltutorial.com/postgresql-select-into 的通知进行了尝试,但我仍然遇到同样的错误。

有人知道如何解决这个问题吗? 谢谢

【问题讨论】:

    标签: sql postgresql azure-data-studio


    【解决方案1】:

    如果您使用的是 Postgres,则 Postgres 等效项是 CREATE TABLE AS

    create table temptable as
        select * 
        from act_hi_taskinst;
    

    【讨论】:

    • 正是我需要的。谢谢
    【解决方案2】:

    这里 - INTO Concept Example

    Insert into temptable
    select *  from act_hi_taskinst;
    

    【讨论】:

      【解决方案3】:

      使用 SQL Azure 选择 INTO SQL Azure 要求所有表都有聚集索引,因此 SELECT INTO 语句创建一个表,不支持创建聚集索引。如果您计划迁移到 SQL Azure,则需要修改代码以使用表创建而不是 SELECT INTO 语句。这适用于临时表(不需要聚集索引)和永久表。

      https://azure.microsoft.com/en-au/blog/select-into-with-sql-azure/

      要解决此问题,您需要创建目标表,然后调用 INSERT INTO。这是一个例子:

      CREATE TABLE #Destination (Id int NOT NULL, [Name] 
      

      【讨论】:

      • 你好@Lenroy Yeung,我的意图是使用“into”自动创建整个表结构。
      猜你喜欢
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 2010-10-03
      • 1970-01-01
      • 2013-05-17
      相关资源
      最近更新 更多