Toto je ekvivalent postgresu
Zadejte TABLE_SCHEMA
a MASKTABLE
níže
Vytvářím MASKTABLE
s prvním vstupem figuríny
DELIMITER $$
CREATE OR REPLACE FUNCTION generate_next_id() RETURNS bigint NOT DETERMINISTIC
MAIN: BEGIN
DECLARE our_epoch bigint;
DECLARE seq_id bigint;
DECLARE now_millis bigint;
DECLARE shard_id int;
DECLARE param bigint ;
SET @our_epoch = 1568873367231;
SET @shard_id = 1;
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "SCHEMANAME" AND TABLE_NAME = "MASKTABLE" into @seq_id;
SELECT FLOOR(UNIX_TIMESTAMP()) * 1000 into @now_millis;
SELECT (@now_millis - @our_epoch) << 23 into @param;
SELECT @param | (@shard_id <<10) into @param;
select @param | (@seq_id) into @param;
RETURN @param;
END MAIN;$$
DELIMITER ;
Použití
select generate_next_id()
Můžete jej použít ve spouštěči jako
CREATE TRIGGER trigger_name
BEFORE INSERT ON TableName
FOR EACH ROW
SET new.id = generate_next_id();