|
14 | 14 | - [JavaScript Evaluation](#javascript-evaluation) |
15 | 15 | - [Examples](#examples) |
16 | 16 | - [Update Functions](#update-functions) |
| 17 | +- [Function Naming Rules](#function-naming-rules) |
17 | 18 | - [Building from Source](#building-from-source) |
18 | 19 | - [License](#license) |
19 | 20 |
|
@@ -63,7 +64,7 @@ SELECT js_create_scalar('function_name', 'function_code'); |
63 | 64 |
|
64 | 65 | ### Parameters |
65 | 66 |
|
66 | | -- **function_name**: The name of your custom function |
| 67 | +- **function_name**: The name of your custom function (see [Function Naming Rules](#function-naming-rules)) |
67 | 68 | - **function_code**: JavaScript code that defines your function. Must be in the form `function(args) { /* your code here */ }` |
68 | 69 |
|
69 | 70 | ### Example |
@@ -97,7 +98,7 @@ SELECT js_create_aggregate('function_name', 'init_code', 'step_code', 'final_cod |
97 | 98 |
|
98 | 99 | ### Parameters |
99 | 100 |
|
100 | | -- **function_name**: The name of your custom aggregate function |
| 101 | +- **function_name**: The name of your custom aggregate function (see [Function Naming Rules](#function-naming-rules)) |
101 | 102 | - **init_code**: JavaScript code that initializes variables for the aggregation |
102 | 103 | - **step_code**: JavaScript code that processes each row. Must be in the form `function(args) { /* your code here */ }` |
103 | 104 | - **final_code**: JavaScript code that computes the final result. Must be in the form `function() { /* your code here */ }` |
@@ -143,7 +144,7 @@ SELECT js_create_window('function_name', 'init_code', 'step_code', 'final_code', |
143 | 144 |
|
144 | 145 | ### Parameters |
145 | 146 |
|
146 | | -- **function_name**: The name of your custom window function |
| 147 | +- **function_name**: The name of your custom window function (see [Function Naming Rules](#function-naming-rules)) |
147 | 148 | - **init_code**: JavaScript code that initializes variables |
148 | 149 | - **step_code**: JavaScript code that processes each row. Must be in the form `function(args) { /* your code here */ }` |
149 | 150 | - **final_code**: JavaScript code that computes the final result. Must be in the form `function() { /* your code here */ }` |
@@ -196,7 +197,7 @@ SELECT js_create_collation('collation_name', 'collation_function'); |
196 | 197 |
|
197 | 198 | ### Parameters |
198 | 199 |
|
199 | | -- **collation_name**: The name of your custom collation |
| 200 | +- **collation_name**: The name of your custom collation (see [Function Naming Rules](#function-naming-rules)) |
200 | 201 | - **collation_function**: JavaScript code that compares two strings. Must return a negative number if the first string is less than the second, zero if they are equal, or a positive number if the first string is greater than the second. |
201 | 202 |
|
202 | 203 | ### Example |
@@ -336,6 +337,36 @@ FROM exam_results; |
336 | 337 |
|
337 | 338 | Due to a constraint in [SQLite](https://www3.sqlite.org/src/info/cabab62bc10568d4), it is not possible to update or redefine a user-defined function using the same database connection that was used to initially register it. To modify an existing JavaScript function, the update must be performed through a separate database connection. |
338 | 339 |
|
| 340 | +## Function Naming Rules |
| 341 | + |
| 342 | +Function names must comply with SQLite identifier rules and must be unique within the database and its schema. |
| 343 | + |
| 344 | +### Unquoted Identifiers |
| 345 | +These must follow typical SQL naming conventions: |
| 346 | +- Must begin with a letter (A-Z or a-z) or an underscore `_` |
| 347 | +- May contain letters, digits (0-9), and underscores `_` |
| 348 | +- Are case-insensitive |
| 349 | +- Cannot match a reserved keyword unless quoted |
| 350 | + |
| 351 | +**Examples:** |
| 352 | +- Valid: `identifier1`, `_temp`, `user_name` |
| 353 | +- Invalid: `123abc`, `select`, `identifier-name` |
| 354 | + |
| 355 | +### Quoted Identifiers |
| 356 | +SQLite supports delimited identifiers, which allow almost any character, as long as the identifier is properly quoted. |
| 357 | + |
| 358 | +You can use: |
| 359 | +- Double quotes: `"identifier name"` |
| 360 | +- Square brackets (Microsoft-style): `[identifier name]` |
| 361 | +- Backticks (MySQL-style): `` `identifier name` `` |
| 362 | + |
| 363 | +These quoting styles are interchangeable in SQLite. Inside a quoted identifier, you can include: |
| 364 | +- Spaces: `"my column"` |
| 365 | +- Special characters: `"name@domain"`, `"price€"`, `"weird!name"` |
| 366 | +- Reserved SQL keywords: `"select"`, `"group"` |
| 367 | + |
| 368 | +Quoted identifiers are case-sensitive. |
| 369 | + |
339 | 370 | ## Building from Source |
340 | 371 |
|
341 | 372 | See the included Makefile for building instructions: |
|
0 commit comments