Functions
Table of Contents
Version Control Functions
Doltgres provides functions for version control features that update the state of the database, such as creating or deleting branches, making a new commit, etc. Each is named after the Git command that it imitates. So for example, the following Git command:
Is modeled as the following SQL statement in Doltgres:
Version control features that only inspect the state of the database are modeled as system tables or table functions instead.
The functions in this section are also available as stored procedures. Whether you access them as functions or as procedures is up to you. The main difference is that in Postgres, stored procedures cannot return values, but functions can. This means that if your application needs the result of an operation, it must use the function version, rather than the procedure version.
Otherwise, these statements are equivalent:
DOLT_ADD()
DOLT_ADD()Adds working changes to staged for this session.
After adding tables to the staged area, they can be committed with DOLT_COMMIT().
Options
table: Table(s) to add to the list tables staged to be committed. The abbreviation '.' can be used to add all tables.
-A: Stages all tables with changes.
Output Schema
Example
DOLT_BACKUP()
DOLT_BACKUP()Sync with a configured backup. Other backup commands not supported via SQL yet.
Output Schema
Example
DOLT_BRANCH()
DOLT_BRANCH()Create, delete, and rename branches.
To list branches, use the DOLT_BRANCHES system table, instead of the DOLT_BRANCH() function.
To look up the current branch, use the @@<dbname>_head_ref system variable, or the active_branch() SQL function, as shown in the examples section below.
WARNING: In a multi-session server environment, Dolt will prevent you from deleting or renaming a branch in use in another session. You can force renaming or deletion by passing the --force option, but be aware that active clients on other sessions will no longer be able to execute statements after their active branch is removed and will need to end their session and reconnect.
Notes
Branch names have a few restrictions which are similar to the constraints Git puts on branch names. Dolt's branches are a little more restrictive, as ASCII characters are required. Rules are as follows:
All characters must be ASCII (7 Bit)
May not start with '.' (period)
May not contain '..' (two periods)
May not contain '@{'
May not contain ASCII control characters
May not contain characters: ':', '?', '[', '\', '^', '~', '*'
May not contain whitespace (spaces, tabs, newlines)
May not end with '/'
May not end with '.lock'
May not be HEAD (case insensitive)
May not be indistinguishable from a commit hash. 32 characters, where all characters are 0-9 or a-z (case sensitive)
The dolt_branch() function implicitly commits the current transaction and begins a new one.
Options
-c, --copy: Create a copy of a branch. Must be followed by the name of the source branch to copy and the name of the new branch to create. Without the --force option, the copy will fail if the new branch already exists.
-m, --move: Move/rename a branch. Must be followed by the current name of an existing branch and a new name for that branch. Without the --force option, renaming a branch in use on another server session will fail. Be aware that forcibly renaming or deleting a branch in use in another session will require that session to disconnect and reconnect before it can execute statements again.
-d, --delete: Delete a branch. Must be followed by the name of an existing branch to delete. Without the --force option, deleting a branch in use on another server session will fail. Be aware that forcibly renaming or deleting a branch in use in another session will require that session to disconnect and reconnect before it can execute statements again.
-f, --force: When used with the --copy option, allows for recreating a branch from another branch, even if the branch already exists. When used with the --move or --delete options, force will allow you to rename or delete branches in use in other active server sessions, but be aware that this will require those other sessions to disconnect and reconnect before they can execute statements again.
-D: Shortcut for --delete --force.
Output Schema
Examples
DOLT_CHECKOUT()
DOLT_CHECKOUT()Switches this session to a different branch.
With table names as arguments, restores those tables to their contents in the current HEAD.
Note, unlike the Git command-line, if you have a modified working set, those changes remain on the branch you modified after a DOLT_CHECKOUT(). Uncommitted changes in the working set do not transfer to the checked out branch as on the command line. We modified this behavior in the SQL context because multiple users may be connected to the same branch. Having one user bring changes from various other branches with them when they switch branches is too disruptive in the multi-tenant SQL context.
Notes
DOLT_CHECKOUT() with a branch argument has two side effects on your session state:
The session's current database, as returned by
SELECT DATABASE(), is now the unqualified database name.For the remainder of this session, references to the unqualified name of this database will resolve to the branch checked out.
See the comments after the statements below for an example of this behavior, and also read Using Branches
Options
-b: Create a new branch with the given name and switch to it.
-B: Similar to -b, but will move a branch if it already exists.
-t: When creating a new branch, set up 'upstream' configuration.
Output Schema
Example
DOLT_CHERRY_PICK()
DOLT_CHERRY_PICK()Apply the changes introduced by an existing commit.
Apply changes from existing commit and creates a new commit from the current HEAD.
Options
No options for this function.
Output Schema
Example
For the below example consider the following set up of main and mybranch branches:
We want to cherry-pick only the change introduced in commit hash 'k318tpmqn4l97ofpaerato9c3m70lc14', which inserts 1 and 2 to the table. Specifying 'mybranch~1' instead of the commit hash also works.
DOLT_CLEAN()
DOLT_CLEAN()Deletes untracked tables in the working set.
Deletes only specified untracked tables if table names are passed as arguments.
With --dry-run flag, tests whether removing untracked tables will return with zero status.
Options
--dry-run: Test removing untracked tables from working set.
Output Schema
Example
DOLT_CLONE()
DOLT_CLONE()Clones an existing Dolt database into a new database within the current Dolt environment. The existing database must be specified as an argument, either as a file URL that points to an existing Dolt database on disk, or a doltremote URL for remote hosted database (e.g. a database hosted in an S3 bucket). An additional argument can optionally be supplied to specify the name of the new, cloned database, otherwise the current name of the existing database will be used.
NOTE: When cloning from a file URL, you must currently include the .dolt/noms subdirectories. For more details see the GitHub tracking issue, dolt#1860.
Options
--remote: Name of the remote to be added to the new, cloned database. The default is 'origin'.
-b, --branch: The branch to be cloned. If not specified all branches will be cloned.
--depth: Clone a single branch and limit history to the given commit depth.
Output Schema
Examples
DOLT_COMMIT()
DOLT_COMMIT()Commits staged tables to HEAD.
DOLT_COMMIT() also implicitly commits the current transaction.
Options
-m, --message: Use the given <msg> as the commit message. Required
-a, --all: Stages all modified tables (but not newly created tables) before committing.
-A, --ALL: Stages all tables (including new tables) before committing.
--allow-empty: Allow recording a commit that has the exact same data as its sole parent. This is usually a mistake, so it is disabled by default. This option bypasses that safety.
--skip-empty: Record a commit only if there are changes to be committed. The commit operation will be a no-op, instead of an error, if there are no changes staged to commit. An error will be thrown if --skip-empty is used with --allow-empty.
--date: Specify the date used in the commit. If not specified the current system time is used.
--author: Specify an explicit author using the standard "A U Thor [email protected]" format.
--amend: Overwrite the commit message for the current HEAD, rather than creating a new commit.
Output Schema
Examples
DOLT_CONFLICTS_RESOLVE()
DOLT_CONFLICTS_RESOLVE()When a merge finds conflicting changes, it documents them in the dolt_conflicts table. A conflict is between two versions: ours (the rows at the destination branch head) and theirs (the rows at the source branch head). dolt conflicts resolve will automatically resolve the conflicts by taking either the ours or theirs versions for each row.
Options
<table>: List of tables to be resolved. '.' can be used to resolve all tables.
--ours: For all conflicts, take the version from our branch and resolve the conflict.
--theirs: For all conflicts, take the version from their branch and resolve the conflict.
Output Schema
Examples
DOLT_FETCH()
DOLT_FETCH()Fetch refs, along with the objects necessary to complete their histories and update remote-tracking branches.
Options
No options for this function.
Output Schema
Example
Notes
Dropping the second argument, or passing NULL, will result is using the default refspec.
DOLT_GC()
DOLT_GC()Cleans up unreferenced data from the database to reclaim disk space.
Options
--shallow Performs a faster but less thorough garbage collection.
Output Schema
DOLT_MERGE()
DOLT_MERGE()Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.
Any resulting merge conflicts must be resolved before the transaction can be committed or a new Dolt commit created. DOLT_MERGE() creates a new commit for any successful merge with auto-generated commit message if not defined.
Options
--no-ff: Create a merge commit even when the merge resolves as a fast-forward.
--squash: Merges changes to the working set without updating the commit history
-m <msg>, --message=<msg>: Use the given as the commit message. This is only useful for --non-ff commits.
--abort: Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
--author: Specify an explicit author using the standard A U Thor <[email protected]> format.
When merging a branch, your session state must be clean. COMMIT orROLLBACK any changes, then DOLT_COMMIT() to create a new dolt commit on the target branch.
If the merge causes conflicts or constraint violations, you must resolve them using the dolt_conflicts system tables before the transaction can be committed. See Dolt system tables for details.
Output Schema
Example
DOLT_PULL()
DOLT_PULL()Fetch from and integrate with another database or a local branch. In its default mode, dolt pull is shorthand for dolt fetch followed by dolt merge <remote>/<branch>.
Any resulting merge conflicts must be resolved before the transaction can be committed or a new Dolt commit created.
Options
--no-ff: Create a merge commit even when the merge resolves as a fast-forward.
--squash: Merges changes to the working set without updating the commit history
--force: Ignores any foreign key warnings and proceeds with the commit.
When merging a branch, your session state must be clean. COMMIT orROLLBACK any changes, then DOLT_COMMIT() to create a new Dolt commit on the target branch.
If the merge causes conflicts or constraint violations, you must resolve them using the dolt_conflicts system tables before the transaction can be committed. See Dolt system tables for details.
Output Schema
Example
DOLT_PURGE_DROPPED_DATABASES()
DOLT_PURGE_DROPPED_DATABASES()Permanently deletes any dropped databases that are being held in a temporary holding area. When a Doltgres database is dropped, it is moved to a temporary holding area where the dolt_undrop() function can restore it. The dolt_purge_dropped_databases() function clears this holding area and permanently deletes any data from those databases. This action is not reversible, so callers should be cautious about using it. The main benefit of using this function is to reclaim disk space used by the temporary holding area. Because this is a destructive operation, callers must have SUPER privileges in order to execute it.
Example
DOLT_PUSH()
DOLT_PUSH()Updates remote refs using local refs, while sending objects necessary to complete the given refs.
Options
--force: Update the remote with local history, overwriting any conflicting history in the remote.
Output Schema
Example
DOLT_REBASE()
DOLT_REBASE()Rewrites commit history for the current branch by replaying commits, allowing the commits to be reordered, squashed, or dropped. The commits included in the rebase plan are the commits reachable by the current branch, but NOT reachable from the branch specified as the argument when starting a rebase (also known as the upstream branch). This is the same as Git and Dolt's "two dot log" syntax, or |upstreamBranch|..|currentBranch|.
For example, consider the commit graph below, where a feature branch has branched off of a main branch, and both branches have added commits:
If we rebase from the feature branch using the main branch as our upstream, the default rebase plan will include commits G, H, and I, since those commits are reachable from our current branch, but NOT reachable from the upstream branch. By default, the changes from those same commits will be reapplied, in the same order, to the tip of the upstream branch main. The resulting commit graph will then look like:
Rebasing is useful to clean and organize your commit history, especially before merging a feature branch back to a shared branch. For example, you can drop commits that contain debugging or test changes, or squash or fixup small commits into a single commit, or reorder commits so that related changes are adjacent in the new commit history.
Limitations
Currently only interactive rebases are supported, and there is no support for resolving conflicts that arise while executing a rebase plan. If applying a commit creates a conflict, the rebase will be automatically aborted.
Options
--interactive or -i: Start an interactive rebase. Currently only interactive rebases are supported, so this option is required.
--continue: Continue an interactive rebase after adjusting the rebase plan stored in dolt_rebase.
--abort: Abort a rebase in progress.
Output Schema
Example
DOLT_REMOTE()
DOLT_REMOTE()Adds a remote for a database at given url, or removes an existing remote with its remote-tracking branches and configuration settings. To list existing remotes, use the dolt_remotes system table.
Output Schema
Example
DOLT_RESET()
DOLT_RESET()With no arguments, resets staged tables to their HEAD state. Can also be used to reset a database to a specific commit.
Like other data modifications, after a reset you must COMMIT the transaction for any changes to affected tables to be visible to other clients.
Notes
With the
--hardoption, thedolt_reset()function implicitly commits the current transaction and begins a new one.
Options
--hard: Resets the working tables and staged tables. Any changes to tracked tables in the working tree since are discarded.
--soft: Does not touch the working tables, but removes all tables staged to be committed. This is the default behavior.
Output Schema
Example
DOLT_REVERT()
DOLT_REVERT()Reverts the changes introduced in a commit, or set of commits. Creates a new commit from the current HEAD that reverses the changes in all the specified commits. If multiple commits are given, they are applied in the order given.
Options
--author=<author>: Specify an explicit author using the standard A U Thor <[email protected]> format.
Output Schema
Example
DOLT_TAG()
DOLT_TAG()Creates a new tag that points at specified commit ref, or deletes an existing tag. To list existing tags, use dolt_tags system table.
Options
-m: Use the given message as the tag message.
-d: Delete a tag.
--author: Specify an explicit author using the standard "A U Thor [email protected]" format.
Output Schema
Example
DOLT_UNDROP()
DOLT_UNDROP()Restores a dropped database. See the dolt_purge_dropped_databases() function for info on how to permanently remove dropped databases.
Options
dolt_undrop() takes a single argument – the name of the dropped database to restore. When called without any arguments, dolt_undrop() returns an error message that contains a list of all dropped databases that are available to be restored.
Example
DOLT_VERIFY_CONSTRAINTS()
DOLT_VERIFY_CONSTRAINTS()Verifies that working set changes (inserts, updates, and/or deletes) satisfy the defined table constraints. If any constraints are violated they are written to the DOLT_CONSTRAINT_VIOLATIONS table.
DOLT_VERIFY_CONSTRAINTS by default does not detect constraints for row changes that have been previously committed. The --all option can be specified if you wish to validate all rows in the database. If FOREIGN_KEY_CHECKS has been disabled in prior commits, you may want to use the --all option to ensure that the current state is consistent and no violated constraints are missed.
Arguments and Options
<table>: The table(s) to check constraints on. If omitted, checks all tables.
-a, --all: Verifies constraints against every row.
-o, --output-only: Disables writing results to the DOLT_CONSTRAINT_VIOLATIONS system table.
Output Schema
Example
For the below examples consider the following schema:
A simple case:
Using --all to verify all rows:
Checking specific tables only:
Informational Functions
ACTIVE_BRANCH()
ACTIVE_BRANCH()The ACTIVE_BRANCH() function returns the name of the currently active branch for this session.
DOLT_MERGE_BASE()
DOLT_MERGE_BASE()DOLT_MERGE_BASE() returns the hash of the common ancestor between two branches.
Consider the following branch structure:
The following would return the hash of commit E:
DOLT_HASHOF()
DOLT_HASHOF()The DOLT_HASHOF() function returns the commit hash of a branch or other commit spec.
DOLT_HASHOF_TABLE()
DOLT_HASHOF_TABLE()The DOLT_HASHOF_TABLE() function returns the value hash of a table. The hash is the hash of all the rows in the table, and is dependent on their serialization format. As such a table could have the same rows, but different hashes if the serialization format has changed, however if a table hash has not changed, then it's guaranteed that the table's data has not changed.
This function can be used to watch for changes in data by storing previous hashes in your application and comparing them to the current hash. For example, you can use this function to get the hash of a table named color like so:
DOLT_HASHOF_DB()
DOLT_HASHOF_DB()The DOLT_HASHOF_DB() function returns the value hash of the entire versioned database. The hash is the hash of all tables (schema and data) in the database, and includes additional versioned items such as stored procedures and triggers. The hash does not include unversioned items such as tables which have been ignored. The function takes an optional argument to specify a branch or one of the values of 'STAGED', 'WORKING', or 'HEAD' (default no argument call is equivalent to 'WORKING').
This function can be used to watch for changes in the database by storing previous hashes in your application and comparing them to the current hash. For example, you can use this function to get the hash of the entire database like so:
It should be noted that if you are connected to branch 'main' and you call dolt_hashof_db('feature'), the hash may be different than if you were connected to branch 'feature' and called dolt_hashof_db(). This happens if there exist changes to the working set on branch 'feature' that have not been committed. Calling dolt_hashof_db('feature') while on 'main' is equivalent to calling dolt_hashof_db('HEAD') while on branch 'feature'.
The general recommendation when trying to look for changes to the database is to connect to the branch you want to use, then call dolt_hashof_db() without any arguments. Any change in the hash means that the database has changed.
DOLT_VERSION()
DOLT_VERSION()The DOLT_VERSION() function returns the version string for the Dolt binary.
HAS_ANCESTOR()
HAS_ANCESTOR()The HASH_ANCESTOR(target, ancestor) function returns a boolean indicating whether a candidate ancestor commit is in the commit graph of the target ref.
Consider the example commit graph from above:
A hypothetical example where we substitute letters for commit hashes would look like:
Table Functions
Table functions operate like regular SQL functions, but instead of returning a single, scalar value, a table function returns rows of data, just like a table. Dolt's table functions have several restrictions in how they can be used in queries. For example, you cannot currently alias a table function or join a table function with another table or table function.
DOLT_DIFF()
DOLT_DIFF()The DOLT_DIFF() table function calculates the differences in a table's data at any two commits in the database. Each row in the result set describes how a row in the underlying table has changed between the two commits, including the row's values at to and from commits and the type of change (i.e. added, modified, or removed). DOLT_DIFF() is an alternative to the dolt_commit_diff_$tablename system table. You should generally prefer the system tables when possible, since they have less restrictions on use. However, some use cases, such as viewing a table data diff containing schema changes or viewing the three dot diff, can be easier to view with the DOLT_DIFF table function.
The main difference between the results of the DOLT_DIFF() table function and the dolt_commit_diff_$tablename system table is the schema of the returned results. dolt_commit_diff_$tablename generates the resulting schema based on the table's schema at the currently checked out branch. DOLT_DIFF() will use the schema at the from_commit for the from_ columns and the schema at the to_commit for the to_ columns. This can make it easier to view diffs where the schema of the underlying table has changed.
Note that the DOLT_DIFF() table function currently requires that argument values be literal values.
Options
The DOLT_DIFF() table function takes either two or three required arguments:
from_revision— the revision of the table data for the start of the diff. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~").to_revision— the revision of the table data for the end of the diff. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~").from_revision..to_revision— gets the two dot diff, or revision of table data between thefrom_revisionandto_revision. This is equivalent todolt_diff(<from_revision>, <to_revision>, <tablename>).from_revision...to_revision— gets the three dot diff, or revision of table data between thefrom_revisionandto_revision, starting at the last common commit.tablename— the name of the table containing the data to diff.
Schema
The remaining columns are dependent on the schema of the user table as it existed at the from_commit and at the to_commit. For every column X in your table at the from_commit revision, there is a column in the result set named from_X. Likewise, for every column Y in your table at the to_commit revision, there is a column in the result set named to_Y. This is the major difference between the DOLT_DIFF() table function and the dolt_commit_diff_$tablename system table – DOLT_DIFF() uses the two schemas at the to_commit and from_commit revisions to form the to and from columns of the result set, while dolt_commit_diff_$tablename uses only the table schema of the currently checked out branch to form the to and from columns of the result set.
Example
Consider a table named inventory in a database with two branches: main and feature_branch. We can use the DOLT_DIFF() function to calculate a diff of the table data from the main branch to the feature_branch branch to see how our data has changed on the feature branch.
Here is the schema of inventory at the tip of main:
Here is the schema of inventory at the tip of feature_branch:
Based on the schemas at the two revision above, the resulting schema from DOLT_DIFF() will be:
To calculate the diff and view the results, we run the following query:
The results from DOLT_DIFF() show how the data has changed going from main to feature_branch:
Three dot DOLT_DIFF
Let's say the above database has a commit graph that looks like this:
The example above gets the two dot diff, or differences between two revisions: main and feature_branch. dolt_diff('main', 'feature_branch', 'inventory') (equivalent to dolt_diff('main..feature_branch', 'inventory')) outputs the difference from F to D (i.e. with effects of E and F).
Three dot diff is useful for showing differences introduced by a feature branch from the point at which it diverged from the main branch. Three dot diff is used to show pull request diffs.
Therefore, dolt_diff('main...feature_branch') outputs just the differences in feature_branch (i.e. E and F).
Learn more about two vs three dot diff here.
DOLT_DIFF_STAT()
DOLT_DIFF_STAT()The DOLT_DIFF_STAT() table function calculates the data difference stat between any two commits in the database. Schema changes such as creating a new table with no rows, or deleting a table with no rows will return empty result. Each row in the result set describes a diff stat for a single table with statistics information of number of rows unmodified, added, deleted and modified, number of cells added, deleted and modified and total number of rows and cells the table has at each commit.
For keyless tables, this table function only provides the number of added and deleted rows. It returns empty result for tables with no data changes.
Note that the DOLT_DIFF_STAT() table function currently requires that argument values be literal values.
Privileges
DOLT_DIFF_STAT() table function requires SELECT privilege for all tables if no table is defined or for the defined table only.
Options
The DOLT_DIFF_STAT() table function takes three arguments:
from_revision— the revision of the table data for the start of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").to_revision— the revision of the table data for the end of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").from_revision..to_revision— gets the two dot diff stat, or revision of table data between thefrom_revisionandto_revision. This is equivalent todolt_diff_stat(<from_revision>, <to_revision>, <tablename>).from_revision...to_revision— gets the three dot diff stat, or revision of table data between thefrom_revisionandto_revision, starting at the last common commit.tablename— the name of the table containing the data to diff. This argument is optional. When it's not defined, all tables with data diff will be returned.
Schema
Example
Consider we start with a table inventory in a database on main branch. When we make any changes, we can use the DOLT_DIFF_STAT() function to calculate a diff of the table data or all tables with data changes across specific commits.
Here is the schema of inventory at the tip of main:
Here is what table inventory has at the tip of main:
We perform some changes to the inventory table and create new keyless table:
Here is what table inventory has in the current working set:
To calculate the diff and view the results, we run the following query:
The results from DOLT_DIFF_STAT() show how the data has changed going from tip of main to our current working set:
To get a table specific changes going from the current working set to tip of main, we run the following query:
With result of single row:
DOLT_DIFF_SUMMARY()
DOLT_DIFF_SUMMARY()The DOLT_DIFF_SUMMARY() table function is a summary of what tables changed and how between any two commits in the database. Only changed tables will be listed in the result, along with the diff type ('added', 'dropped', 'modified', 'renamed') and whether there are data and schema changes.
It returns empty result if there are no tables with changes.
Note that the DOLT_DIFF() table function currently requires that argument values be literal values.
Privileges
DOLT_DIFF_SUMMARY() table function requires SELECT privilege for all tables if no table is defined or for the defined table only.
Options
The DOLT_DIFF_SUMMARY() table function takes three arguments:
from_revision— the revision of the table data for the start of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").to_revision— the revision of the table data for the end of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").from_revision..to_revision— gets the two dot diff summary, or revision of table data between thefrom_revisionandto_revision. This is equivalent todolt_diff_summary(<from_revision>, <to_revision>, <tablename>).from_revision...to_revision— gets the three dot diff summary, or revision of table data between thefrom_revisionandto_revision, starting at the last common commit.tablename— the name of the table containing the data to diff. This argument is optional. When it's not defined, all tables with data diff will be returned.
Schema
Example
Consider we start with a table inventory in a database on main branch. When we make any changes, we can use the DOLT_DIFF_SUMMARY() function to calculate a diff of the table data or all tables with data changes across specific commits.
Here is the schema of inventory at the tip of main:
Here is what table inventory has at the tip of main:
We perform some changes to the inventory table and create new keyless table:
Here is what table inventory has in the current working set:
To calculate the diff and view the results, we run the following query:
The results from DOLT_DIFF_SUMMARY() show how the data has changed going from tip of main to our current working set:
To get a table specific changes going from the current working set to tip of main, we run the following query:
With result of single row:
DOLT_LOG()
DOLT_LOG()The DOLT_LOG table function gets the commit log for all commits reachable from the provided revision's HEAD (or the current HEAD if no revision is provided).
Note that the DOLT_LOG() table function currently requires that argument values be literal values.
Privileges
DOLT_LOG() table function requires SELECT privilege for all tables.
Options
The DOLT_LOG() table function takes any number of optional revision arguments:
optional_revision: a branch name, tag, or commit ref (with or without an ancestor spec) that specifies which ancestor commits to include in the results. If no revisions are specified, the default is the current branchHEAD.If you'd like to get two dot logs (all commits reachable by
revision2, but NOT reachable byrevision1), you can use..between revisions (DOLT_LOG('revision1..revision2')) or^in front of the revision you'd like to exclude (DOLT_LOG('revision2', '^revision1')). Note: if providing two revisions, one must contain^.If you'd like to get three dot logs (all commits reachable by
revision1orrevision2, excluding commits reachable by BOTHrevision1ANDrevision2), you can use...between revisions (DOLT_LOG('revision1...revision2')).
--min-parents: The minimum number of parents a commit must have to be included in the log.--merges: Equivalent to min-parents == 2, this will limit the log to commits with 2 or more parents.--parents: Shows all parents of each commit in the log.--decorate: Shows refs next to commits. Valid options are short, full, no, and auto. Defaults to "no".--not: Excludes commits reachable by revision.--tables: Limits the log to commits that affect the specified tables. Any number of comma separated tables can be specified.
Schema
Example
Consider we have the following commit graph:
To get the commit log for the main branch, we can use the query:
And it would return commits in reverse-chronological order - D,C, B, and A. The output will look something like:
To get the commit log for the feature branch, we can change the revision in the above query:
And it would return all commits reachable from the HEAD of feature - F, E, C, B, and A.
Two and three dot log
We also support two and three dot log. Two dot log returns commits from a revision, excluding commits from another revision. If we want all commits in feature, excluding commits from main, all of these queries will return commits F and E.
Three dot log returns commits in either revision, excluding commits in BOTH revisions. If we want commits in main OR feature, excluding commits in main AND feature, this query would return commits F, E, and D.
Note: The order of revisions in two dot log matters, but not for three dot log. DOLT_LOG('main..feature') returns F and E, while DOLT_LOG('feature..main') returns just D. DOLT_LOG('main...feature') and DOLT_LOG('feature...main') both return F, E, and D.
Learn more about two vs three dot log here.
DOLT_PATCH()
DOLT_PATCH()Generate the SQL statements needed to patch a table (or all tables) from a starting revision to a target revision. This can be useful when you want to import data into Dolt from an external source, compare differences, and generate the SQL statements needed to patch the original source. Both schema and/or data diff statements are returned if applicable. Some data diff cannot be produced from incompatible schema changes; these are shown as warnings containing which table this occurred on.
The order of the statements is that the schema patch comes first after the data patch. If patching all tables, then we recommend to turn off the foreign key checks (SET foreign_key_checks=0;) before applying these patch statements in order to avoid conflicts.
Privileges
DOLT_PATCH() table function requires SELECT privilege for all tables if no table is defined or for the defined table only.
Options
The DOLT_PATCH() table function takes the following arguments:
from_revision— the revision of the table data for the start of the patch. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").to_revision— the revision of the table data for the end of the patch. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").from_revision..to_revision— gets the two dot patch, or revision of table data between thefrom_revisionandto_revision. This is equivalent todolt_patch(<from_revision>, <to_revision>, <tablename>).from_revision...to_revision— gets the three dot patch, or revision of table data between thefrom_revisionandto_revision, starting at the last common commit.tablename— the name of the table containing the data and/or schema to patch. This argument is optional. When it's not defined, all tables with data and/or schema patch will be returned.
Schema
Example
Consider we start with a table inventory in a database on main branch. When we make any changes, we can use the DOLT_PATCH() function to get SQL patch statements of the table data or all tables with data changes across specific commits.
Here is the schema of inventory at the tip of main:
Here is what table inventory has at the tip of main:
We perform some changes to the inventory table and create new keyless table:
Here is what table inventory has in the current working set:
To get SQL patch statements, we run the following query:
The results from DOLT_PATCH() show how the data has changed going from tip of main to our current working set:
To get a table specific schema patch going from the current working set to tip of main, we run the following query:
With result of single row:
DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY()
DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY()The DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY() table function provides a summary of merge conflicts that would occur when merging a branch. This function is useful for understanding potential conflicts before performing an actual merge operation, allowing you to identify which tables would have conflicts and how many data and schema conflicts would occur.
This function performs a "dry run" merge operation and returns information about conflicts without actually modifying the database or creating a merge commit.
Privileges
DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY() table function requires SELECT privilege for all tables.
Options
The DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY() table function takes two required arguments:
base_branch— the base branch to merge into (e.g. "main").merge_branch— the branch to merge into the base branch (e.g. "feature_branch").
Schema
Example
Consider a scenario where you have a main branch and a feature_branch that have diverged and made conflicting changes to the same data. You can preview the conflicts that would occur when merging feature_branch into main:
This might return results like:
Note that if there are schema conflicts the data conflicts are not able to be calculated and that column will be null.
This output indicates that merging feature_branch into main would create conflicts in three tables:
The
userstable would have 3 data conflicts and no schema conflictsThe
orderstable would have 1 data conflict and no schema conflictsThe
productstable would have 2 schema conflicts
If there would be no conflicts, the function returns an empty result set.
This information helps you understand the scope of conflicts before attempting a merge, allowing you to plan conflict resolution strategies or coordinate with other developers who may have made conflicting changes.
DOLT_PREVIEW_MERGE_CONFLICTS()
DOLT_PREVIEW_MERGE_CONFLICTS()The DOLT_PREVIEW_MERGE_CONFLICTS() table function provides detailed information about merge conflicts that would occur when merging a branch. Unlike DOLT_PREVIEW_MERGE_CONFLICTS_SUMMARY() which only provides a count of conflicts per table, this function returns the actual conflicting rows with their base, ours, and theirs values.
This function performs a "dry run" merge operation and returns detailed conflict information without actually modifying the database or creating a merge commit. The results are similar to what you would see in the dolt_conflicts_$TABLENAME system tables after performing an actual merge, but without making any changes to the database.
Privileges
DOLT_PREVIEW_MERGE_CONFLICTS() table function requires SELECT privilege for all tables.
Options
The DOLT_PREVIEW_MERGE_CONFLICTS() table function takes three required arguments:
base_branch— the base branch to merge into (e.g. "main").merge_branch— the branch to merge into the base branch (e.g. "feature_branch").table_name— the name of the table to preview conflicts for.
Schema
The schema of the DOLT_PREVIEW_MERGE_CONFLICTS() function depends on the schema of the specified table. For each column X in the table, the result set contains three columns:
base_X— the value of column X at the common ancestor commitour_X— the value of column X in the base branchtheir_X— the value of column X in the merge branch
Additionally, the result set includes these metadata columns:
Where:
from_root_ish— the commit hash of the merge branch (the "from" branch of the merge). This hash can be used to identify which merge produced a conflict, since conflicts can accumulate across merges. User code generally ignores this column.our_diff_typeandtheir_diff_typeindicate whether the row was "added", "modified", or "removed" in the corresponding branchdolt_conflict_idis a unique identifier for each conflict
Example
Consider a table users with columns id, name, and email that has conflicts between main and feature_branch. You can preview the specific conflicts:
This might return results like:
This output shows:
Row 1: Both branches modified the same user but with different changes (name vs email)
Row 2: Both branches added a new user with the same ID but different data
To view only specific columns for easier reading:
Keyless Tables
For keyless tables (tables without primary keys), the behavior is slightly different. Dolt uses content-based addressing to identify rows, so conflicts in keyless tables are detected when the same content would be added or modified differently on each branch.
Keyless tables include additional columns not present in tables with primary keys:
base_cardinality— the number of occurrences of the conflicting row in the merge ancestor commitour_cardinality— the number of occurrences of the conflicting row in the base branchtheir_cardinality— the number of occurrences of the conflicting row in the merge branch
Consider a keyless table logs with columns timestamp, level, and message:
This might return results like:
In this example, the same log entry exists once in the base branch, but appears 3 times in our branch and 2 times in their branch, creating a conflict about cardinality (how many times the row should appear).
Notes
If there are no conflicts in the specified table, the function returns an empty result set.
This detailed view allows you to examine the exact differences that would cause conflicts and plan appropriate resolution strategies before performing the actual merge. The results are similar to what you would see in the dolt_conflicts_$TABLENAME system tables after an actual merge, but without making any changes to your database.
DOLT_REFLOG()
DOLT_REFLOG()The DOLT_REFLOG() table function shows the history of named refs (e.g. branches and tags), which is useful when you want to understand how a branch or tag has changed over time to reference different commits, particularly for information that isn't surfaced through the dolt_log system table or dolt_log() table function. For example, if you use dolt_reset() to change the commit a branch points to, you can use dolt_reflog() to see what commit the branch was pointing to before it was moved to that commit. Another common use case for dolt_reflog() is to recreate a branch or tag that was accidentally deleted. The example section below shows how to recreate a deleted branch.
The data from Dolt's reflog comes from Dolt's journaling chunk store. This data is local to a Dolt database and never included when pushing, pulling, or cloning a Dolt database. This means when you clone a Dolt database, it will not have any reflog data until you perform operations that change what commit branches or tags reference.
Dolt's reflog is similar to Git's reflog, but there are a few differences:
The Dolt reflog currently only supports named references, such as branches and tags, and not any of Git's special refs (e.g.
HEAD,FETCH-HEAD,MERGE-HEAD).The Dolt reflog can be queried for the log of references, even after a reference has been deleted. In Git, once a branch or tag is deleted, the reflog for that ref is also deleted and to find the last commit a branch or tag pointed to you have to use Git's special
HEADreflog to find the commit, which can sometimes be challenging. Dolt makes this much easier by allowing you to see the history for a deleted ref so you can easily see the last commit a branch or tag pointed to before it was deleted.
Privileges
There are no special privileges required to use the dolt_reflog() table function.
Options
The dolt_reflog() table function can be called with no arguments or with one argument. If called without any arguments, it will return the full reference log, which lists changes from newest to oldest for all tracked references. If called with one argument, that argument is the name of a ref to query. This can be the name of a branch (e.g. "myBranch") or the name of a tag (e.g. "v1.1.4") or it can be the fully qualified ref path (e.g. "refs/heads/myBranch"). The ref_name parameter is case-insensitive.
The dolt_reflog() table function can also be called with the --all flag to show all refs, including hidden refs, such as DoltHub workspace refs.
Schema
Example
The example below shows how to recreate a branch that was deleted by finding the last commit it referenced in Dolt's reflog.
DOLT_SCHEMA_DIFF()
DOLT_SCHEMA_DIFF()The DOLT_SCHEMA_DIFF() table function calculates the schema difference between any two commits in the database. Each row in the result set describes how a table was altered between the two commits, including the table's create statement at to and from commits.
Note that the DOLT_SCHEMA_DIFF() table function currently requires that argument values be literal values.
Privileges
DOLT_SCHEMA_DIFF() table function requires SELECT privilege for all tables if no table is defined or for the defined table only.
Options
The DOLT_SCHEMA_DIFF() table function takes three arguments:
from_revision— the revision of the table data for the start of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").to_revision— the revision of the table data for the end of the diff. This argument is required. This may be a commit, tag, branch name, or other revision specifier (e.g. "main~", "WORKING", "STAGED").from_revision..to_revision— gets the two dot diff, or revision of table schema between thefrom_revisionandto_revision. This is equivalent todolt_schema_diff(<from_revision>, <to_revision>, [<tablename>]).from_revision...to_revision— gets the three dot diff, or revision of table schema between thefrom_revisionandto_revision, starting at the last common commit.tablename— the name of the table to diff. This argument is optional. When it's not defined, all tables with schema diffs will be returned.
Schema
Example
For this example, we'll consider three tables within the context of two branches: main and feature_branch.
These are the tables on main: employees, inventory, vacations. These are the tables on feature_branch: inventory, photos, trips.
To figure out how these tables changed, we run the following query:
The results from DOLT_SCHEMA_DIFF() show how the schema for all tables has changed going from tip of main to tip of feature_branch:
Let's look at the returned data.
The first row has values in
from_table_nameandfrom_create_statementcolumns, whileto_table_nameandto_create_statementcolumns are empty. This means that betweenmainandfeature_branch, the tableemployeeswas deleted.The second row has identical values for
from_table_nameandto_table_name, butfrom_create_statementis different fromto_create_statement. This means the table's schema changed betweenmainandfeature_branch.The third row is similar to the first row, except its
to_*columns are empty, andfrom_*columns are set. This means that betweenmainandfeature_branch, the tablephotoswas added.Finally, the last row has mostly identical
from_create_statementandto_create_statementcolumns, but differentfrom_table_nameandto_table_namecolumns. This means the table was renamed changed betweenmainandfeature_branch.
We invoked DOLT_SCHEMA_DIFF() with branch names, but we could have used any revision specifier. For example, we could have used commit hashes or tag names, and would have gotten the same results.
Using tags or commit hashes:
So far, we have always supplied just the first two parameters, the from and to revisions, but we have not specified the optional table parameter, so DOLT_SCHEMA_DIFF() returned schema diffs of all changed tables. We can scope DOLT_SCHEMA_DIFF() to a specific table simply by specifying it as the last parameter.
Let's try this with the inventory table.
We will see this set of results:
When a table is renamed, we can specify either the "old" table name, or the "new" table name, and we will receive the same results. The following two queries will provide the same results:
Here are the results:
Finally, we can flip the order of the revisions to get the schema diff in the opposite direction.
The above query will produce this output:
Note the difference between this select and the previous dolt_schema_diff('main', 'feature_branch') invocation:
First row shows that the table
photoswas deletedSecond row show the creation of
employeestableThird row has the
from_create_statementandto_create_statementcolumns swappedFourth row shows the inverse rename of
tripstovacations
Example query
You can try calling DOLT_SCHEMA_DIFF() against the DoltHub docs_examples DB, by getting the diff of schemas between schema_diff_v1 and schema_diff_v2 tags, which correspond to main and feature_branch branches from these examples.
DOLT_QUERY_DIFF()
DOLT_QUERY_DIFF()The DOLT_QUERY_DIFF() table function calculates the data difference between any two queries, producing a table similar to the DOLT_DIFF() table function.
Privileges
DOLT_QUERY_DIFF() table function requires SELECT privilege for all tables used in each query.
Example
For this example, we have the table t in two branches main and other.
On main, the table t has the following data:
On other, the table t has the following data:
We can use the DOLT_QUERY_DIFF() table function to calculate the difference between the two tables:
Note
Query diff is performed brute force and thus, will be slow for large result sets. The algorithm is super linear (n^2) on the size of the results sets. Over time, we will optimize this to use features of the storage engine to improve performance.
Last updated
