postgresql 修改列添加列等操作


 

-- 添加列

ALTER table planting_identification_tag add identification_tag_unique_id varchar(64);

ALTER table trace_env_factor add sample_value varchar(1024);
ALTER table trace_env_factor add image varchar(1024);


-- 添加備注
COMMENT ON COLUMN "public"."planting_identification_tag"."identification_tag_unique_id" IS '標簽庫uniqueId';


-- 修改列名

ALTER TABLE trace_env_factor  RENAME  trace_env_index_unique_id  to trace_env_factor_unique_id ;
ALTER TABLE trace_env_factor  RENAME  env_index_name  to name ;
ALTER TABLE trace_env_factor  RENAME  env_index_code  to unit ;

ALTER TABLE trace_env_factor  RENAME  env_index_description  to description ;


-- 修改字段類型
alter table trace_env_factor alter column unit type varchar(64);


-- 修改表名
alter table trace_env_index rename to trace_env_factor;
-- 刪除表
 drop table  company;

 


--刪除列 -存在該字段才刪除 

alter table bas_cm_tenant_verification drop column if exists verify_type;

 

修改/添加 列默認值

alter table trace_code_batch alter column   expected_quantity                set default 0;   
ALTER TABLE trace_env ALTER COLUMN value set  not null;

刪除 列默認值

ALTER TABLE table_name ALTER COLUMN column_name DROP DEFAULT;

ALTER TABLE trace_planting_record ALTER COLUMN phenophase_name DROP not null;

 

 

插入數據

insert into procudt_certification(
    gmt_create,
    gmt_modified,
    procudt_certification_unique_id,
    certification_name,
    certification_image,
    agro_product_id,
    farm_isolation_id,
    is_deleted
    )
    values(
    now(),
    now(),
    uuid_in(md5(random()::text || now()::text)::cstring),
    '無公害農產品',
    'https://asd/123.png',
    '',
    '6386dec95b1243f2944f4ac9559db40b',
    0
    );

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM