将此语句 DROP PROCEDURE IF EXISTS schema_change;$$ CREATE PROCEDURE schema_change() BEGIN CREATE TABLE IF NOT EXISTS `bis_record_upload_list` ( `pkid` int(11) NOT NULL AUTO_INCREMENT, `hash_code` varchar(255) DEFAULT NULL COMMENT '检验码', `path` varchar(255) DEFAULT NULL COMMENT '路径', PRIMARY KEY (`pkid`), UNIQUE KEY `hash_code` (`hash_code`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'bis_record_upload_list' AND column_name = 'hash_code') THEN alter table bis_record_upload_list add `hash_code` varchar(255) DEFAULT NULL COMMENT '检验码'; END IF; END;$$ CALL schema_change();$$ DROP PROCEDURE IF EXISTS schema_change;$$修改成kingbase语句
时间: 2024-04-06 17:33:48 浏览: 158
在Kingbase中,可以使用PL/PGSQL语言编写存储过程,将上述语句转换为Kingbase语句如下:
DROP FUNCTION IF EXISTS schema_change();
CREATE OR REPLACE FUNCTION schema_change() RETURNS void AS $$
BEGIN
CREATE TABLE IF NOT EXISTS "bis_record_upload_list" (
"pkid" serial NOT NULL,
"hash_code" character varying(255) DEFAULT NULL,
"path" character varying(255) DEFAULT NULL,
CONSTRAINT "bis_record_upload_list_pk" PRIMARY KEY ("pkid"),
CONSTRAINT "bis_record_upload_list_hash_code_key" UNIQUE ("hash_code")
);
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = 'bis_record_upload_list' AND column_name = 'hash_code') THEN
ALTER TABLE "bis_record_upload_list" ADD COLUMN "hash_code" character varying(255) DEFAULT NULL;
END IF;
END;
$$ LANGUAGE PLPGSQL;
SELECT schema_change();
DROP FUNCTION IF EXISTS schema_change();
阅读全文