CHMAC

Name

CHMAC -- change maclabel of table's row

Synopsis

[ WITH [ RECURSIVE ] with_query [, ...] ]
CHMAC [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    SET maclabel = label
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

Description

CHMAC changes the mandate label of the maclabel column in all rows that satisfy the condition.

The optional RETURNING clause causes CHMAC to compute and return value(s) based on each row actually CHMACd. Any expression using the table's columns, and/or columns of other tables mentioned in FROM, can be computed. The new (post-CHMAC) values of the table's columns are used. The syntax of the RETURNING list is identical to that of the output list of SELECT.

You must have the CHMAC privilege on the table, or at least on the column(s) that are listed to be CHMACd. You must also have the SELECT privilege on any column whose values are read in the expressions or condition.

Parameters

with_query

The WITH clause allows you to specify one or more subqueries that can be referenced by name in the CHMAC query. See Section 7.8 and SELECT for details.

table_name

The name (optionally schema-qualified) of the table to CHMAC. If ONLY is specified before the table name, matching rows are CHMACd in the named table only. If ONLY is not specified, matching rows are also CHMACd in any tables inheriting from the named table. Optionally, * can be specified after the table name to explicitly indicate that descendant tables are included.

alias

A substitute name for the target table. When an alias is provided, it completely hides the actual name of the table. For example, given CHMAC foo AS f, the remainder of the CHMAC statement must refer to this table as f not foo.

expression

An expression to assign to the column. The expression can use the old values of this and other columns in the table.

sub-SELECT

A SELECT sub-query that produces as many output columns as are listed in the parenthesized column list preceding it. The sub-query must yield no more than one row when executed. If it yields one row, its column values are assigned to the target columns; if it yields no rows, NULL values are assigned to the target columns. The sub-query can refer to old values of the current row of the table being CHMACd.

from_list

A list of table expressions, allowing columns from other tables to appear in the WHERE condition and the CHMAC expressions. This is similar to the list of tables that can be specified in the FROM Clause of a SELECT statement. Note that the target table must not appear in the from_list, unless you intend a self-join (in which case it must appear with an alias in the from_list).

condition

An expression that returns a value of type boolean. Only rows for which this expression returns true will be CHMACd.

cursor_name

The name of the cursor to use in a WHERE CURRENT OF condition. The row to be CHMACd is the one most recently fetched from this cursor. The cursor must be a non-grouping query on the CHMAC's target table. Note that WHERE CURRENT OF cannot be specified together with a Boolean condition. See DECLARE for more information about using cursors with WHERE CURRENT OF.

output_expression

An expression to be computed and returned by the CHMAC command after each row is CHMACd. The expression can use any column names of the table named by table_name or table(s) listed in FROM. Write * to return all columns.

output_name

A name to use for a returned column.

Outputs

On successful completion, an CHMAC command returns a command tag of the form

CHMAC count

The count is the number of rows CHMACd, including matched rows whose values did not change. Note that the number may be less than the number of rows that matched the condition when CHMACs were suppressed by a BEFORE CHMAC trigger. If count is 0, no rows were CHMACd by the query (this is not considered an error).

If the CHMAC command contains a RETURNING clause, the result will be similar to that of a SELECT statement containing the columns and values defined in the RETURNING list, computed over the row(s) CHMACd by the command.

Notes

When a FROM clause is present, what essentially happens is that the target table is joined to the tables mentioned in the from_list, and each output row of the join represents an CHMAC operation for the target table. When using FROM you should ensure that the join produces at most one output row for each row to be modified. In other words, a target row shouldn't join to more than one row from the other table(s). If it does, then only one of the join rows will be used to CHMAC the target row, but which one will be used is not readily predictable.

Because of this indeterminacy, referencing other tables only within sub-selects is safer, though often harder to read and slower than using a join.

Examples

CHMAC statistics in a summary table to match the current data:

CHMAC summary s SET maclabel = '{1,2}';

Compatibility

There is no MAC LABEL command in the SQL standard.