BLOB_APPEND()
Efficient concatenation of blobs
BLOB
BLOB_APPEND(expr1, expr2 [, exprN ... ])
| Parameter | Description |
|---|---|
exprN |
An expression of a type convertible to |
The BLOB_APPEND function concatenates blobs without creating intermediate BLOBs, avoiding excessive memory consumption and growth of the database file.The BLOB_APPEND function takes two or more arguments and adds them to a BLOB which remains open for further modification by a subsequent BLOB_APPEND call.
The resulting BLOB is left open for writing instead of being closed when the function returns.In other words, the BLOB can be appended as many times as required.The engine marks the BLOB returned by BLOB_APPEND with an internal flag, BLB_close_on_read, and closes it automatically when needed.
The first argument determines the behaviour of the function:
-
NULL: new, emptyBLOB SUB_TYPE TEXTis created, using the connection character set as the character set -
permanent
BLOB(from a table) or temporaryBLOBwhich was already closed: newBLOBis created with the same subtype and, if subtype isTEXTthe same character set, populated with the content of the originalBLOB. -
temporary unclosed
BLOBwith theBLB_close_on_readflag (e.g. created by another call toBLOB_APPEND): used as-is, remaining arguments are appended to thisBLOB -
other data types: a new
BLOB SUB_TYPE TEXTis created, populated with the original argument converted to string.If the original value is a character type, its character set is used (for string literals, the connection character set), otherwise the connection character set.
Other arguments can be of any type.The following behavior is defined for them:
-
NULLs are ignored (behaves as empty string) -
BLOBs, if necessary, are transliterated to the character set of the first argument and their contents are appended to the result -
other data types are converted to strings (as usual) and appended to the result
The BLOB_APPEND function returns a temporary unclosed BLOB with the BLB_close_on_read flag.If the first argument is such a temporary unclosed BLOB (e.g. created by a previous call to BLOB_APPEND), it will be used as-is, otherwise a new BLOB is created.Thus, a series of operations like blob = BLOB_APPEND (blob, …) will result in the creation of at most one BLOB (unless you try to append a BLOB to itself).This blob will be automatically closed by the engine when the client reads it, assigns it to a table, or uses it in other expressions that require reading the content.
|
Warning
|
Important caveats for
BLOB_APPEND
|
|
Note
|
Testing a blob for |
|
Tip
|
Use |