简体   繁体   中英

How to change the position of column in postgresql without dumping

I know the only workaround is to dump the table and then recreate the whole database with correct positioning of the required columns.

But the problem is one of the columns is a foreign key to many tables in the database so it would not be possible to just delete the whole table. Also I cannot delete any column as the foreign key column lies to the last of the table. Please give me a solution.

If this question is a duplicate please give me the link to the correct answer.

edit: for more clarification i want to add rows using the insert command and the problem is the second last column is of the type serial. My main aim is to not touch the serial column while giving the insert command

All you need is a custom insert statement,

For example,

Your table looks like this,

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

and the insert statement can be written as

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 >
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM