Skip to content

Instantly share code, notes, and snippets.

@ninodafonte
Last active August 17, 2017 13:48
Show Gist options
  • Save ninodafonte/6539074 to your computer and use it in GitHub Desktop.
Save ninodafonte/6539074 to your computer and use it in GitHub Desktop.
Create autoincrement with a specific number (date) #postgres
set @autoincrementValue = (SELECT DATE_FORMAT(NOW(), '%y%m%d') * 10000);
SET @s = CONCAT("alter table NameOfYourTable auto_increment=", @autoincrementValue);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment