Retrieve the last query ID
MD_LAST_QUERY_ID() is a scalar function that returns the UUID of the most recent query sent to the MotherDuck server from the current DuckDB connection. This is the same QUERY_ID that appears in the QUERY_HISTORY and RECENT_QUERIES views.
The function returns NULL if no query has been sent to the server yet on the current connection.
Syntax
SELECT MD_LAST_QUERY_ID();
Return type
UUID: the unique identifier of the last query, or NULL if no server-side query has been run.
Example usage
Get the ID of your last query
SELECT MD_LAST_QUERY_ID();
Look up details for last query from this connection in the query history
SELECT *
FROM MD_INFORMATION_SCHEMA.QUERY_HISTORY
WHERE QUERY_ID = MD_LAST_QUERY_ID();