Skip to content

Commit 4d4fbac

Browse files
mariadb-stefan-hinzgitbook-bot
authored andcommitted
GITBOOK-2191: DOCS-6071: Document OLD_VALUE() function.
1 parent 578e9de commit 4d4fbac

File tree

7 files changed

+55
-18
lines changed

7 files changed

+55
-18
lines changed

server/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,7 @@
19921992
* [MASTER\_GTID\_WAIT](reference/sql-functions/secondary-functions/miscellaneous-functions/master_gtid_wait.md)
19931993
* [MASTER\_POS\_WAIT](reference/sql-functions/secondary-functions/miscellaneous-functions/master_pos_wait.md)
19941994
* [NAME\_CONST](reference/sql-functions/secondary-functions/miscellaneous-functions/name_const.md)
1995+
* [OLD\_VALUE](reference/sql-functions/secondary-functions/miscellaneous-functions/values-value.md)
19951996
* [RELEASE\_ALL\_LOCKS](reference/sql-functions/secondary-functions/miscellaneous-functions/release_all_locks.md)
19961997
* [RELEASE\_LOCK](reference/sql-functions/secondary-functions/miscellaneous-functions/release_lock.md)
19971998
* [SLEEP](reference/sql-functions/secondary-functions/miscellaneous-functions/sleep.md)
@@ -2000,7 +2001,7 @@
20002001
* [UUID\_SHORT](reference/sql-functions/secondary-functions/miscellaneous-functions/uuid_short.md)
20012002
* [UUID\_v4](reference/sql-functions/secondary-functions/miscellaneous-functions/uuid_v4.md)
20022003
* [UUID\_v7](reference/sql-functions/secondary-functions/miscellaneous-functions/uuid_v7.md)
2003-
* [VALUES / VALUE](reference/sql-functions/secondary-functions/miscellaneous-functions/values-value.md)
2004+
* [VALUES / VALUE](reference/sql-functions/secondary-functions/miscellaneous-functions/values-value-1.md)
20042005
* [Special Functions](reference/sql-functions/special-functions/README.md)
20052006
* [Dynamic Columns Functions](reference/sql-functions/special-functions/dynamic-columns-functions/README.md)
20062007
* [COLUMN\_ADD](reference/sql-functions/special-functions/dynamic-columns-functions/column_add.md)

server/reference/sql-functions/function-and-operator-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ description: >-
531531
| [UUIDv4](secondary-functions/miscellaneous-functions/uuid_v4.md) | Returns a Universal Unique Identifier v4 | [MariaDB 11.7](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.7/what-is-mariadb-117) |
532532
| [UUIDv7](secondary-functions/miscellaneous-functions/uuid_v7.md) | Returns a Universal Unique Identifier v7 | [MariaDB 11.7](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.7/what-is-mariadb-117) |
533533
| [UUID\_SHORT](secondary-functions/miscellaneous-functions/uuid_short.md) | Return short universal identifier | |
534-
| [VALUES or VALUE](secondary-functions/miscellaneous-functions/values-value.md) | Refer to columns in INSERT ... ON DUPLICATE KEY UPDATE | |
534+
| [VALUES or VALUE](secondary-functions/miscellaneous-functions/values-value-1.md) | Refer to columns in INSERT ... ON DUPLICATE KEY UPDATE | |
535535
| [VAR\_POP](aggregate-functions/var_pop.md) | Population standard variance | |
536536
| [VAR\_SAMP](aggregate-functions/var_samp.md) | Returns the sample variance | |
537537
| [VARIANCE](aggregate-functions/variance.md) | Population standard variance | |
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: >-
3+
Access values in ON DUPLICATE KEY UPDATE. This function retrieves the value
4+
that would have been inserted into a column if no key conflict occurred.
5+
---
6+
7+
# VALUES / VALUE
8+
9+
## Syntax
10+
11+
```sql
12+
VALUE(col_name)
13+
```
14+
15+
## Description
16+
17+
In an [INSERT ... ON DUPLICATE KEY UPDATE](../../../sql-statements/data-manipulation/inserting-loading-data/insert-on-duplicate-key-update.md) statement, you can use the `VALUES(col_name)` function in the [UPDATE](../../../sql-statements/data-manipulation/changing-deleting-data/update.md) clause to refer to column values from the [INSERT](../../../sql-statements/data-manipulation/inserting-loading-data/insert.md) portion of the statement. In other words, `VALUES(col_name)` in the `UPDATE` clause refers to the value of col\_name that would be inserted, had no duplicate-key conflict occurred. This function is especially useful in multiple-row inserts.
18+
19+
The `VALUES()` function is meaningful only in `INSERT ... ON DUPLICATE KEY UPDATE` statements and returns `NULL` otherwise.
20+
21+
This function was renamed to `VALUE()`, because it's incompatible with the standard Table Value Constructors syntax.
22+
23+
The `VALUES()` function can still be used but only in `INSERT ... ON DUPLICATE KEY UPDATE` statements; it's a syntax error otherwise.
24+
25+
## Examples
26+
27+
```sql
28+
INSERT INTO t (a,b,c) VALUES (1,2,3),(4,5,6)
29+
ON DUPLICATE KEY UPDATE c=VALUE(a)+VALUE(b);
30+
```
31+
32+
<sub>_This page is licensed: GPLv2, originally from_</sub> [<sub>_fill\_help\_tables.sql_</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)
33+
34+
{% @marketo/form formId="4316" %}

server/reference/sql-functions/secondary-functions/miscellaneous-functions/values-value.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ description: >-
44
that would have been inserted into a column if no key conflict occurred.
55
---
66

7-
# VALUES / VALUE
7+
# OLD\_VALUE
8+
9+
{% hint style="info" %}
10+
This function is available from MariaDB 13.0.
11+
{% endhint %}
812

913
## Syntax
1014

1115
```sql
12-
VALUE(col_name)
16+
OLD_VALUE(val)
1317
```
1418

1519
## Description
1620

17-
In an [INSERT ... ON DUPLICATE KEY UPDATE](../../../sql-statements/data-manipulation/inserting-loading-data/insert-on-duplicate-key-update.md) statement, you can use the `VALUES(col_name)` function in the [UPDATE](../../../sql-statements/data-manipulation/changing-deleting-data/update.md) clause to refer to column values from the [INSERT](../../../sql-statements/data-manipulation/inserting-loading-data/insert.md) portion of the statement. In other words, `VALUES(col_name)` in the `UPDATE` clause refers to the value of col\_name that would be inserted, had no duplicate-key conflict occurred. This function is especially useful in multiple-row inserts.
18-
19-
The `VALUES()` function is meaningful only in `INSERT ... ON DUPLICATE KEY UPDATE` statements and returns `NULL` otherwise.
20-
21-
This function was renamed to `VALUE()`, because it's incompatible with the standard Table Value Constructors syntax.
22-
23-
The `VALUES()` function can still be used but only in `INSERT ... ON DUPLICATE KEY UPDATE` statements; it's a syntax error otherwise.
21+
In the `RETURNING` clause of an [`UPDATE`](../../../sql-statements/data-manipulation/changing-deleting-data/update.md) statement, `OLD_VALUE()` returns the value before the update. The function is meaningful only in this context.
2422

2523
## Examples
2624

2725
```sql
28-
INSERT INTO t (a,b,c) VALUES (1,2,3),(4,5,6)
29-
ON DUPLICATE KEY UPDATE c=VALUE(a)+VALUE(b);
26+
UPDATE t SET a=a+1 RETURNING OLD_VALUE(a) AS old, a as new;
27+
+------+------+
28+
| old | new |
29+
+------+------+
30+
| 1 | 2 |
31+
+------+------+
3032
```
3133

3234
<sub>_This page is licensed: GPLv2, originally from_</sub> [<sub>_fill\_help\_tables.sql_</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

server/reference/sql-statements/data-manipulation/inserting-loading-data/insert-on-duplicate-key-update.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If more than one unique index is matched, only the first is updated. It is not r
4949

5050
If the table has an [AUTO\_INCREMENT](../../../data-types/auto_increment.md) [primary key](../../../../mariadb-quickstart-guides/mariadb-indexes-guide.md#primary-key) and the statement inserts or updates a row, the [LAST\_INSERT\_ID()](../../../sql-functions/secondary-functions/information-functions/last_insert_id.md) function returns its AUTO\_INCREMENT value.
5151

52-
The [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value.md) function can only be used in a `ON DUPLICATE KEY UPDATE` clause and has no meaning in any other context. It returns the column values from the `INSERT` portion of the statement. This function is particularly useful for multi-rows inserts.
52+
The [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value-1.md) function can only be used in a `ON DUPLICATE KEY UPDATE` clause and has no meaning in any other context. It returns the column values from the `INSERT` portion of the statement. This function is particularly useful for multi-rows inserts.
5353

5454
The [IGNORE](ignore.md) and [DELAYED](insert-delayed.md) options are ignored when you use `ON DUPLICATE KEY UPDATE`.
5555

@@ -199,7 +199,7 @@ INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
199199
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
200200
```
201201

202-
See the [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value.md) function for more.
202+
See the [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value-1.md) function for more.
203203

204204
## See Also
205205

@@ -210,7 +210,7 @@ See the [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-func
210210
* [Concurrent Inserts](concurrent-inserts.md)
211211
* [INSERT - Default & Duplicate Values](insert-default-duplicate-values.md)
212212
* [INSERT IGNORE](insert-ignore.md)
213-
* [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value.md)
213+
* [VALUES()](../../../sql-functions/secondary-functions/miscellaneous-functions/values-value-1.md)
214214

215215
<sub>_This page is licensed: CC BY-SA / Gnu FDL_</sub>
216216

server/reference/sql-statements/geometry-constructors/miscellaneous-gis-functions/st_geohash.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: >-
88
# ST\_GeoHash
99

1010
{% hint style="info" %}
11-
ST\_GeoHash is available from [MariaDB 12.0](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/release-notes-mariadb-12.0-rolling-releases/what-is-mariadb-120).
11+
ST\_GeoHash is available from [MariaDB 12.0](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/12.0/what-is-mariadb-120).
1212
{% endhint %}
1313

1414
## Syntax

server/server-management/install-and-upgrade-mariadb/upgrading/upgrading-to-unmaintained-mariadb-releases/upgrading-from-mariadb-102-to-mariadb-103.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The following options should be removed or renamed if you use them in your [opti
9999

100100
#### Functions
101101

102-
* As a result of implementing Table Value Constructors, the [VALUES function](../../../../reference/sql-functions/secondary-functions/miscellaneous-functions/values-value.md) has been renamed to VALUE().
102+
* As a result of implementing Table Value Constructors, the [VALUES function](../../../../reference/sql-functions/secondary-functions/miscellaneous-functions/values-value-1.md) has been renamed to VALUE().
103103
* Functions that used to only return 64-bit now can return 32-bit results ([MDEV-12619](https://jira.mariadb.org/browse/MDEV-12619)). This could cause incompatibilities with strongly-typed clients.
104104

105105
#### mysqldump

0 commit comments

Comments
 (0)