Documentation Home
MySQL 9.2 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.7Mb
PDF (A4) - 40.8Mb
Man Pages (TGZ) - 259.6Kb
Man Pages (Zip) - 366.9Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.2 Reference Manual  /  ...  /  CREATE LIBRARY Statement

15.1.16 CREATE LIBRARY Statement

Press CTRL+C to copy
CREATE LIBRARY [IF NOT EXISTS] [database.]library LANGUAGE language AS code

This statement creates a JavaScript code library in the named database, if any. If no database is specified, the library is created in the current database. The library name may be any valid SQL identifier. LANGUAGE must be JavaScript (case-insensitive).

code is a string consisting of JavaScript code which is checked for validity at creation time; invalid code causes the statement to be rejected with an error. The code string can be dollar-quoted or single-quoted; it can also be double-quoted as long as ANSI_QUOTES SQL mode is not set.

To execute CREATE LIBRARY, the user must have the CREATE ROUTINE privilege.

To use a library created within a stored program using this statement, the user must have the EXECUTE privilege. This is checked whenever a function or procedure using the library is created.

The first statement creates a JavaScript library named lib1 in the jslib database. The SELECT statement that follows it displays the row in the Inormation Schema LIBRARIES table corresponding to the library just created.

Press CTRL+C to copy
mysql> CREATE LIBRARY IF NOT EXISTS jslib.lib1 LANGUAGE JAVASCRIPT -> AS $$ $> export function f(n) { $> return n $> } $> $$; Query OK, 0 rows affected (0.02 sec) mysql> SELECT * FROM information_schema.LIBRARIES -> WHERE LIBRARY_SCHEMA='jslib'\G *************************** 1. row *************************** LIBRARY_CATALOG: def LIBRARY_SCHEMA: jslib LIBRARY_NAME: lib1 LIBRARY_DEFINITION: export function f(n) { return n } LANGUAGE: JAVASCRIPT CREATED: 2024-12-16 16:36:44 LAST_ALTERED: 2024-12-16 16:36:44 SQL_MODE: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE, NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION CREATOR: me@localhost 1 row in set (0.00 sec)

CREATE LIBRARY was added in MySQL 9.2.0.

See Section 27.3.8, “Using JavaScript Libraries”, for more information and examples.