These functions implement a row locking mechanism to support long transactions. They are provided primarily for implementors of the Web Feature Service specification.

# Long Transaction Support

For the locking mechanism to operate correctly the serializable transaction isolation level must be used.

AddAuth

Adds an authorization token to be used in the current transaction.

    			boolean AddAuth
    			text  auth_token

### Description

Adds an authorization token to be used in the current transaction.

Adds the current transaction identifier and authorization token to a temporary table called `temp_lock_have_table`.

Availability: 1.1.3

### Examples

    		SELECT LockRow('towns', '353', 'priscilla');
    		BEGIN TRANSACTION;
    			SELECT AddAuth('joey');
    			UPDATE towns SET geom = ST_Translate(geom,2,2) WHERE gid = 353;
    		COMMIT;

    		---Error--
    		ERROR:  UPDATE where "gid" = '353' requires authorization 'priscilla'

### See Also

LockRow

CheckAuth

Creates a trigger on a table to prevent/allow updates and deletes of rows based on authorization token.

    				integer CheckAuth
    				text  a_schema_name
    				text  a_table_name
    				text  a_key_column_name

    				integer CheckAuth
    				text  a_table_name
    				text  a_key_column_name

### Description

Creates trigger on a table to prevent/allow updates and deletes of rows based on an authorization token. Identify rows using <rowid_col> column.

If a_schema_name is not passed in, then searches for table in current schema.

If an authorization trigger already exists on this table function errors.

If Transaction support is not enabled, function throws an exception.

Availability: 1.1.3

### Examples

    			SELECT CheckAuth('public', 'towns', 'gid');
    			result
    			------
    			0

### See Also

EnableLongTransactions

DisableLongTransactions

Disables long transaction support.

    			  text DisableLongTransactions

### Description

Disables long transaction support. This function removes the long transaction support metadata tables, and drops all triggers attached to lock-checked tables.

Drops meta table called `authorization_table` and a view called `authorized_tables` and all triggers called `checkauthtrigger`

Availability: 1.1.3

### Examples

    SELECT DisableLongTransactions();
    --result--
    Long transactions support disabled

### See Also

EnableLongTransactions

EnableLongTransactions

Enables long transaction support.

    			  text EnableLongTransactions

### Description

Enables long transaction support. This function creates the required metadata tables. It must be called once before using the other functions in this section. Calling it twice is harmless.

Creates a meta table called `authorization_table` and a view called `authorized_tables`

Availability: 1.1.3

### Examples

    SELECT EnableLongTransactions();
    --result--
    Long transactions support enabled

### See Also

DisableLongTransactions

LockRow

Sets lock/authorization for a row in a table.

    			integer LockRow
    			text  a_schema_name
    			text  a_table_name
    			text  a_row_key
    			text an_auth_token
    			timestamp expire_dt

    			integer LockRow
    			text  a_table_name
    			text  a_row_key
    			text an_auth_token
    			timestamp expire_dt

    			integer LockRow
    			text  a_table_name
    			text  a_row_key
    			text an_auth_token

### Description

Sets lock/authorization for a specific row in a table. `an_auth_token` is a text value. `expire_dt` is a timestamp which defaults to now() + 1 hour. Returns 1 if lock has been assigned, 0 otherwise (i.e. row is already locked by another auth.)

Availability: 1.1.3

### Examples

    SELECT LockRow('public', 'towns', '2', 'joey');
    LockRow
    -------
    1

    --Joey has already locked the record and Priscilla is out of luck
    SELECT LockRow('public', 'towns', '2', 'priscilla');
    LockRow
    -------
    0

### See Also

UnlockRows

UnlockRows

Removes all locks held by an authorization token.

    			integer UnlockRows
    			text  auth_token

### Description

Removes all locks held by specified authorization token. Returns the number of locks released.

Availability: 1.1.3

### Examples

    		SELECT LockRow('towns', '353', 'priscilla');
    		SELECT LockRow('towns', '2', 'priscilla');
    		SELECT UnLockRows('priscilla');
    		UnLockRows
    		------------
    		2

### See Also

LockRow