【问题标题】:How to change the position of column in postgresql without dumping如何在不转储的情况下更改 postgresql 中列的位置
【发布时间】:2020-06-24 13:52:59
【问题描述】:

我知道唯一的解决方法是转储表,然后重新创建整个数据库并正确定位所需的列。

但问题是其中一列是数据库中许多表的外键,因此不可能只删除整个表。我也不能删除任何列,因为外键列位于表的最后。请给我一个解决方案。

如果这个问题是重复的,请给我正确答案的链接。

编辑:为了更清楚,我想使用插入命令添加行,问题是倒数第二列是串行类型。我的主要目的是在给出插入命令时不要触摸串行列

【问题讨论】:

  • 您能解释一下为什么要更改列的位置吗?您可以使用所需的列位置创建一个视图并使用它,或者如果您使用 Windows,请尝试 fishcodelib.com/database.htm 更改列位置
  • 因为我想使用插入命令添加行,问题是倒数第二列是串行类型。我的主要目标是在给出插入命令时不要触摸串行列
  • 您可以轻松地处理插入语句中的列。 insert into table( type columns name with comma seperation and exclude the serial column) value(put corresponding values)
  • 您可以插入特定列:INSERT INTO table (column1, column3, column6) VALUES ('data1', 'data2', 'data6');
  • 哦,谢谢,我没想到 XD。

标签: sql postgresql


【解决方案1】:

您只需要一个自定义插入语句,

例如,

你的桌子是这样的,

CREATE TABLE "public"."ada" (
    
    "trandate" date, 
    "locname" text, 
    "totusers" integer, 
    "actusers" integer, 
    "datausage" integer, 
    "issues" integer, 
    "id" serial PRIMARY KEY, 
    "issuessolved" integer
);

插入语句可以写成

INSERT INTO "public"."ada" (
    "trandate"
    ,"locname"
    ,"totusers"
    ,"actusers"
    ,"datausage"
    ,"issues"
    ,"issuessolved"
    )
VALUES (
    < trandate
    ,date >
    ,< locname
    ,text >
    ,< totusers
    ,integer >
    ,< actusers
    ,integer >
    ,< datausage
    ,integer >
    ,< issues
    ,integer >
    ,< issuessolved
    ,integer >
    );

【讨论】:

  • 非常感谢老兄。
猜你喜欢
  • 2013-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
相关资源
最近更新 更多