Skip to content

Feature suggestion: LAST_INSERT_UUID() #7547

@gitasmus

Description

@gitasmus

In his blog Tim pointed out the usefulness of UUIDs: https://www.dolthub.com/blog/2023-10-27-uuid-keys/

A minimal example could look as follows. Create table with a UUID as default primary key:

CREATE TABLE uuid_test(
    id BINARY(16) DEFAULT (UUID_TO_BIN(UUID())),
    some_text VARCHAR(255),
    PRIMARY KEY (id)
);

Next Insert a row without giving an ID:

INSERT INTO uuid_test (some_text) VALUES ('abc');

If we are interested in the last inserted ID

SELECT LAST_INSERT_ID();

does not return the UUID as it's return type is hard-wired to UNSIGNED BIGINT.

In analogy to LAST_INSERT_ID() it would thus be nice if dolt provided a feature that is also missing in MySQL: LAST_INSERT_UUID(), which would retur the last auto-created UUID.

The lack of such a LAST_INSERT_UUID() function could be circumvented in MySQL and dolt with a TRIGGER as described in
https://stackoverflow.com/questions/4687196/mysql-insert-id-or-something-like-that-to-return-last-mysql-uuid

A dedicated LAST_INSERT_UUID() function in dolt would IMHO be appropriate to the importance of UUIDs (and convenient), but would break the compatibility with MySQL. The alternative of implementing the return type of LAST_INSERT_ID() in a more general way to allow for ID to be UNSIGNED BIGINT, UUID() to be VARCHAR(36) and UUID_TO_BIN(UUID()) to be BINARY(16) could be even more logical but would cause even more compatibility confusion with MySQL.

Perhaps, it would be the better approach to ask for such a feature in MySQL first and then ask for the compatibility of dolt here ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions