Editing versioned data in PostgreSQL using multiversioned views and SQL
You can edit versioned data in a geodatabase by editing a multiversioned view created on the data.
There are several functions installed with ArcSDE that help you work with multiversioned views. These functions and their descriptions are as follows:
Function |
Purpose |
Syntax and description |
---|---|---|
sde.sde_create_version |
Create a new geodatabase version. Always edit your own, separate version; multiple editors cannot edit the same version using multiversioned views. |
SELECT sde.sde_create_version ('<parent_name>', '<version_name>', <rule_code>, <access_code>, '<description>') <parent_version> is the version from which your version is created. <child_version> is the name for the version you are creating. <name_rule> indicates whether the name specified for the version should be taken as given (2), or a unique name should be created when a duplicate name is specified (1). <access> is the permission level for the version; either 0 for Private, 1 for Public, or 2 for Protected. <description> is a text description of the child version. |
sde.sde_set_current_version |
Set which geodatabase version you will access. |
SELECT sde.sde_set_current_version('<version_name>'); The <version_name> is the name of the geodatabase version to which you want to connect. |
sde.sde_edit_version |
Start and end an edit session. |
SELECT sde.sde_edit_version('<version_name>',<1 or 2>) Specify 1 to start the edit session. Specify 2 to end it. |
sde.sde_delete_version |
Delete a geodatabase version. |
SELECT sde.sde_delete_version('<version_name>'); |
When you edit versioned tables through multiversioned views, changes are made to the delta tables, and row ID (object ID) values for new records are automatically generated. However, unlike editing versioned data in an ArcGIS edit session, no internal version reconciliation is done with these edits.
Additionally, an exclusive lock is placed on the state that the version references when you start an edit session on a multiversioned view. Therefore, it is strongly recommended that multiversioned views not be used to edit the DEFAULT version or any version that may be subject to simultaneous editing or reconciliation by other users because conflicts will not be detected and locks will block other users. Instead, create your own version specifically for your multiversioned view edit session.
- Version management operations, such as reconciling, resolving conflicts, and posting, must be done using the ArcGIS software. Improper version management can lead to geodatabase corruption when working with views.
- Never use database management system (DBMS) tools to update any row ID (object ID) field maintained by ArcSDE in the database. These object ID fields are allocated and managed by the geodatabase and, therefore, should not be altered using SQL.
- Never edit the DEFAULT version of the geodatabase using SQL. Starting an edit session on a version obtains an exclusive lock on the state that the version references. If you lock the DEFAULT version, you prevent ArcGIS users from connecting to the geodatabase.
The following steps guide you through creating a multiversioned view, creating a version in which to perform edits, setting the version to edit, starting an edit session, performing some edits through the multiversioned view, stopping the edit session, committing your edits to the database, and deleting the version created for the edits. In the examples, the multiversioned view created to perform the edits on the table is code_mv, and the version created and used for editing is mvedits.
Remember that the dataset you edit through a multiversioned view must already have been registered as versioned.
-
At an MS-DOS (Windows) or shell (Linux) command prompt, execute the sdetable utility to create a multiversioned view.
sdetable –o create_mv_view –T code_mv –t code_enf –i sde:postgresql:myserver –D code –u sarja –p not4U
-
Log in to the database from psql and create a new version in which to perform your edits.
SELECT sde.sde_create_version ('sde.DEFAULT', 'mvedits', 2, 1, 'version for edits');
-
Set the version for the edit session to the child version you just created.
SELECT sde.sde_set_current_version('mvedits');
-
Start an edit session by executing the sde_edit_version function and specifying 1.
The 1 indicates an edit session should be started.
SELECT sde.sde_edit_version('mvedits',1);
-
Perform the first edit through the multiversioned view using SQL.
In this example, an existing record is updated.
UPDATE code_mv SET propowner = 'C. Industry' WHERE vid = 2233
-
When you have finished all your edits for this session, stop the edit session by executing the sde_edit_version function, but this time, specify 2.
The 2 indicates the edit session should be closed.
SELECT sde.sde_edit_version('mvedits',2);
-
When all editing is done, reconcile and post edits through ArcGIS Desktop, then you can delete the geodatabase version you created in step 2. Or if you decide you do not want the changes, you can delete the version you created in step 2 without reconciling and posting your edits.
SELECT sde.sde_delete_version('mvedits');
Text enclosed in single quotes is read literally. Therefore, the text you type inside the quote marks must match the case of the text (all upper case, all lower case, or mixed case) as it is stored in the database.