You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/current/_includes/v25.4/misc/session-vars.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@
75
75
| <aid="server-version-num"></a> `server_version_num`| The version of PostgreSQL that CockroachDB emulates. | Version-dependent | Yes | Yes |
76
76
| <aid="session-id"></a> `session_id`| The ID of the current session. | Session-dependent | No | Yes |
77
77
| <aid="session-user"></a> `session_user`| The user connected for the current session. | User in connection string | No | Yes |
78
-
| <a id="sql-safe-updates"></a> `sql_safe_updates` | If `true`, the following potentially unsafe SQL statements are disallowed: [`DROP DATABASE`]({% link {{ page.version.version }}/drop-database.md %}) of a non-empty database and all dependent objects; [`DELETE`]({% link {{ page.version.version }}/delete.md %}) and [`UPDATE`]({% link {{ page.version.version }}/update.md %}) without a `WHERE` clause, unless a [`LIMIT`]({% link {{ page.version.version }}/limit-offset.md %}) clause is included; [`SELECT ... FOR UPDATE`]({% link {{ page.version.version }}/select-for-update.md %}) and [`SELECT ... FOR SHARE`]({% link {{ page.version.version }}/select-for-update.md %}) without a `WHERE` or [`LIMIT`]({% link {{ page.version.version }}/limit-offset.md %}) clause; and [`ALTER TABLE ... DROP COLUMN`]({% link {{ page.version.version }}/alter-table.md %}#drop-column).<br/>For more details, refer to [Allow potentially unsafe SQL statements]({% link {{ page.version.version }}/cockroach-sql.md %}#allow-potentially-unsafe-sql-statements). | `true` for interactive sessions from the [built-in SQL client]({% link {{ page.version.version }}/cockroach-sql.md %}), <br/>`false` for sessions from other clients | Yes | Yes |
78
+
| <a id="sql-safe-updates"></a> `sql_safe_updates` | If `true`, the following potentially unsafe SQL statements are disallowed: [`DROP DATABASE`]({% link {{ page.version.version }}/drop-database.md %}) of a non-empty database and all dependent objects; [`DELETE`]({% link {{ page.version.version }}/delete.md %}) and [`UPDATE`]({% link {{ page.version.version }}/update.md %}) without a `WHERE` clause, unless a [`LIMIT`]({% link {{ page.version.version }}/limit-offset.md %}) clause is included; [`SELECT ... FOR UPDATE`]({% link {{ page.version.version }}/select-for-update.md %}) and [`SELECT ... FOR SHARE`]({% link {{ page.version.version }}/select-for-update.md %}) without a `WHERE` or [`LIMIT`]({% link {{ page.version.version }}/limit-offset.md %}) clause; [`ALTER TABLE ... DROP COLUMN`]({% link {{ page.version.version }}/alter-table.md %}#drop-column); and converting an existing table to [`REGIONAL BY ROW`]({% link {{ page.version.version }}/alter-table.md %}#set-the-table-locality-to-regional-by-row) using `ALTER TABLE ... LOCALITY`, unless a [region column]({% link {{ page.version.version }}/alter-table.md %}#crdb_region) has already been added to the table.<br/>For more details, refer to [Allow potentially unsafe SQL statements]({% link {{ page.version.version }}/cockroach-sql.md %}#allow-potentially-unsafe-sql-statements). | `true` for interactive sessions from the [built-in SQL client]({% link {{ page.version.version }}/cockroach-sql.md %}), <br/>`false` for sessions from other clients | Yes | Yes |
79
79
| <aid="statement-timeout"></a> `statement_timeout`| The amount of time a statement can run before being stopped. <br/>This value can be an `int` (e.g., `10`) and will be interpreted as milliseconds. It can also be an interval or string argument, where the string can be parsed as a valid interval (e.g., `'4s'`). <br/>A value of `0` turns it off. | The value set by the `sql.defaults.statement_timeout`[cluster setting]({% link {{ page.version.version }}/cluster-settings.md %}) (`0s`, by default). | Yes | Yes |
80
80
| <aid="stub-catalog-tables"></a> `stub_catalog_tables`| If `off`, querying an unimplemented, empty [`pg_catalog`]({% link {{ page.version.version }}/pg-catalog.md %}) table will result in an error, as is the case in v20.2 and earlier. If `on`, querying an unimplemented, empty `pg_catalog` table simply returns no rows. |`on`| Yes | Yes |
81
81
| <aid="timezone"></a> `timezone`| The default time zone for the current session. |`UTC`| Yes | Yes |
Copy file name to clipboardExpand all lines: src/current/v25.4/cockroach-sql.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ Flag | Description
87
87
`--file <filename>`<br><br>`-f <filename>` | Read SQL statements from `<filename>`.
88
88
<aname="sql-flag-format"></a> `--format` | How to display table rows printed to the standard output. Possible values: `tsv`, `csv`, `table`, `raw`, `records`, `sql`, `html`.<br><br>**Default:**`table` for sessions that [output on a terminal](#session-and-output-types); `tsv` otherwise<br /><br />This flag corresponds to the `display_format`[client-side option](#client-side-options).
89
89
`--read-only` | Sets the `default_transaction_read_only`[session variable]({% link {{ page.version.version }}/show-vars.md %}#supported-variables) to `on` upon connecting.
90
-
`--safe-updates` | Disallow potentially unsafe SQL statements, including `DELETE` without a `WHERE` clause, `UPDATE` without a `WHERE` clause, and `ALTER TABLE ... DROP COLUMN`.<br><br>**Default:**`true` for [interactive sessions](#session-and-output-types); `false` otherwise<br /><br />Potentially unsafe SQL statements can also be allowed/disallowed for an entire session via the `sql_safe_updates`[session variable]({% link {{ page.version.version }}/set-vars.md %}).
90
+
`--safe-updates`<aname="flag-safe-updates"></a> | Disallow potentially unsafe SQL statements. For the complete list of disallowed statements, refer to the documentation for the [`sql_safe_updates` session variable]({% link {{ page.version.version }}/set-vars.md %}#sql-safe-updates).<br /><br />**Default:**`true` for [interactive sessions](#session-and-output-types); `false` otherwise<br /><br />Potentially unsafe SQL statements can also be allowed/disallowed for an entire session via the [`sql_safe_updates` session variable]({% link {{ page.version.version }}/set-vars.md %}#sql-safe-updates).
91
91
`--set` | Set a [client-side option](#client-side-options) before starting the SQL shell or executing SQL statements from the command line via `--execute`. This flag may be specified multiple times, once per option.<br><br>After starting the SQL shell, the `\set` and `unset` commands can be use to enable and disable client-side options as well.
92
92
`--watch` | Repeat the SQL statements specified with `--execute` or `-e` until a SQL error occurs or the process is terminated. `--watch` applies to all `--execute` or `-e` flags in use.<br />You must also specify an interval at which to repeat the statement, followed by a time unit. For example, to specify an interval of 5 seconds, use `5s`.<br /><br /> Note that this flag is intended for simple monitoring scenarios during development and testing. See the [example](#repeat-a-sql-statement) below.
93
93
@@ -172,6 +172,17 @@ The **Version** and **Cluster ID** details are particularly noteworthy:
172
172
173
173
{% include {{ page.version.version }}/sql/sql-errors.md %}
174
174
175
+
## Allow potentially unsafe SQL statements
176
+
177
+
When running an interactive session, the SQL shell enables only "safe" SQL statements by default. In this state, CockroachDB blocks statements that are likely to cause accidental data loss or unexpected behavior.
178
+
179
+
To allow potentially unsafe statements:
180
+
181
+
- Start the shell with [`--safe-updates=false`](#flag-safe-updates), or
182
+
- In a SQL session, run `SET sql_safe_updates = false` to disable the [`sql_safe_updates` session variable]({% link {{ page.version.version }}/set-vars.md %}#sql-safe-updates) before issuing the statement (and re-enable it afterwards if desired).
183
+
184
+
For details on which statements are disallowed when safe updates are enabled, see the documentation for the [`sql_safe_updates` session variable]({% link {{ page.version.version }}/set-vars.md %}#sql-safe-updates).
185
+
175
186
## Examples
176
187
177
188
{% include {{ page.version.version }}/sql/sql-examples.md %}
0 commit comments