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