<<<<<<< HEAD compress | H2 | SQLDoc
Skip to main content

compress

1. COMPRESS Function

======= compress | H2 Function | SQLDoc

compress

1. COMPRESS Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The COMPRESS function in H2 database is used to compress a given string using the specified compression algorithm.

2. Syntax

The syntax for the COMPRESS function in H2 database is as follows:

COMPRESS(string, algorithm)

Arguments

  • string: The string that needs to be compressed. It should be a valid string value.
  • algorithm: The compression algorithm to be used. It should be a valid algorithm name supported by H2 database.

Return

  • The COMPRESS function returns the compressed version of the input string using the specified algorithm.

3. Notes

  • The COMPRESS function in H2 database compresses the input string using the specified algorithm. The compressed string may have a shorter length than the original string.
  • H2 database supports various compression algorithms such as DEFLATE, GZIP, LZF, LZ4, ZSTD, etc. You can choose the appropriate algorithm based on your requirements.
  • If the input string is NULL, the COMPRESS function will return NULL.
  • It's important to note that the COMPRESS function in H2 database does not automatically decompress the compressed string. To decompress it, you need to use the appropriate decompression function.

4. Examples

Here are a few examples demonstrating the usage of the COMPRESS function in H2 database:

Example 1 - Compressing a string using DEFLATE algorithm:

SELECT COMPRESS('Hello World', 'DEFLATE') AS compressed_string;

Output:

compressed_string
-----------------
x01x9C+KLJ/MS0wAIxLEtKs7MCAAA

Example 2 - Compressing a column values using GZIP algorithm:

CREATE TABLE data (
id INT PRIMARY KEY,
value VARCHAR(100)
);

INSERT INTO data VALUES (1, 'Lorem ipsum dolor sit amet');
INSERT INTO data VALUES (2, 'consectetur adipiscing elit');

SELECT id, value, COMPRESS(value, 'GZIP') AS compressed_value
FROM data;

Output:

id | value                        | compressed_value
---+------------------------------+----------------------------------
1 | Lorem ipsum dolor sit amet | H4sIAAAAAAAA/wrB2k5JTUxOzi9KTS7JzM8vBwDOLlRqSwAAAA==
2 | consectetur adipiscing elit | H4sIAAAAAAAAAyvOzy0yLU4tTi0uSS/PLwcA0uVGpLAAAAA==
  • DECOMPRESS - Decompress a compressed string using the specified algorithm.