Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Postgres中的ALTER表查询_Sql_Postgresql_Ddl - Fatal编程技术网

Sql Postgres中的ALTER表查询

Sql Postgres中的ALTER表查询,sql,postgresql,ddl,Sql,Postgresql,Ddl,我正在尝试将表中一列的数据类型从biginger更改为varchar myproject-# \d+ product_awbstock Table "public.product_awbstock" Column | Type | Modifiers | Storage | Description -------------------+----------------------

我正在尝试将表中一列的数据类型从biginger更改为varchar

myproject-# \d+ product_awbstock
                         Table "public.product_awbstock"
      Column       |           Type           | Modifiers | Storage | Description 
-------------------+--------------------------+-----------+---------+-------------
 airwaybill_number | bigint                   | not null  | plain   | 
 used              | boolean                  | not null  | plain   | 
 created           | timestamp with time zone | not null  | plain   | 
 modified          | timestamp with time zone | not null  | plain   | 
Indexes:
    "product_awbstock_pkey" PRIMARY KEY, btree (airwaybill_number)
    "product_awbstock_used" btree (used)
我使用这个查询,也给出了错误

alter table product_awbstock ALTER  COLUMN airwaybill_number TYPE varchar(15);
错误:外键约束 “awbstock\U id\U refs\U AIRBYBILL\U编号\U d438187b”无法实现

详细信息:“awbstock\u id”和“airbybill\u number”的关键列为 不兼容类型:bigint和字符变化

你应该:

  • 在第一个表上删除主键约束
  • ALTER TABLE product\u awbstock DROP CONSTRAINT product\u awbstock\u pkey

  • 在第二个表上删除外键约束
  • altertable???DROP CONSTRAINT awbstock\u id\u refs\u AIRBYBILL\u编号\u d438187b

  • 更改两个表上的列数据类型
  • ALTER TABLE product\u awbstock ALTER COLUMN airbybill\u number TYPE varchar(15)

    altertable???ALTER列airwaybill_id TYPE varchar(15)

  • 重新创建以前删除的约束
  • ALTER TABLE product\u awbstock ADD CONSTRAINT product\u awbstock\u pkey主键(airwaybill\u编号)


    altertable???添加约束awbstock\u id\u refs\u airbybill\u number\u d438187b外键(awbstock\u id)引用产品awbstock(airbybill\u number)

    错误消息表明此列是从其他表引用的。不同类型的列之间不能有引用。应删除product_awbstock.airwaybill_number和?.awbstock_id之间的约束。您还必须将另一个表的列更改为varchar。但是当前的bigint数据类型有什么问题吗?@jarlh需要将该字段更新为字母数字。