Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/main/asciidoc/query-languages/sql/chapter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ image:../images/edit.png[link="https://github.com/ArcadeData/arcadedb-docs/blob/
| <<in-e,inE()>> | <<avg,avg()>> | <<last,last()>> | <<polygon,polygon()>> | <<vector-avg,vectorAvg()>> | <<strcmpci,strcmpci()>>
| <<both-e,bothE()>> | <<abs,abs()>> | <<intersect,intersect()>> | <<distance,distance()>> | <<vector-add,vectorAdd()>> | <<concat,concat()>>
| <<out-v,outV()>> | <<pow,pow()>> | <<unionall,unionall()>> | | <<vector-subtract,vectorSubtract()>> | <<if,if()>>
| <<in-v,inV()>> | <<sqrt,sqrt()>> | <<distinct,distinct()>> | | <<vector-scale,vectorScale()>> | <<case-expression,case>>
| | | | | | <<ifempty-function,ifempty()>>
| <<both-v,bothV()>> | <<variance,variance()>> | <<difference,difference()>> | | <<vector-variance,vectorVariance()>> | <<ifnull-function,ifnull()>>
| <<traversed-element,traversedElement()>> | <<stddev,stddev()>> | <<symmetricdifference,symmetricDifference()>> | | <<vector-std-dev,vectorStdDev()>> | <<coalesce,coalesce()>>
| <<traversed-vertex,traversedVertex()>> | <<mode,mode()>> | | | <<vector-normalize,vectorNormalize()>> | <<uuid,uuid()>>
| <<traversed-edge,traversedEdge()>> | <<median,median()>> | | | <<vector-is-normalized,vectorisNormalized()>> | <<encode,encode()>>
| <<shortest-path-function,shortestPath()>> | <<percentile,percentile()>> | | | <<vector-has-nan,vectorHasNaN()>> | <<decode,decode()>>
| <<dijkstra,dijkstra()>> | <<random-int,randomInt()>> | | | <<vector-has-inf,vectorHasInf()>> | <<bool-and,bool_and()>>
| <<astar,astar()>> | | | | <<vector-dot-product,vectorDotProduct()>> | <<bool-or,bool_or()>>
| | | | | <<vector-magnitude,vectorMagnitude()>> | <<expand,expand()>>
| | | | | <<vector-l1-norm,vectorL1Norm()>> | <<version,version()>>
| <<in-v,inV()>> | <<sqrt,sqrt()>> | <<distinct,distinct()>> | | <<vector-scale,vectorScale()>> | <<ifempty-function,ifempty()>>
| | | | | | <<ifnull-function,ifnull()>>
| <<both-v,bothV()>> | <<variance,variance()>> | <<difference,difference()>> | | <<vector-variance,vectorVariance()>> | <<coalesce,coalesce()>>
| <<traversed-element,traversedElement()>> | <<stddev,stddev()>> | <<symmetricdifference,symmetricDifference()>> | | <<vector-std-dev,vectorStdDev()>> | <<uuid,uuid()>>
| <<traversed-vertex,traversedVertex()>> | <<mode,mode()>> | | | <<vector-normalize,vectorNormalize()>> | <<encode,encode()>>
| <<traversed-edge,traversedEdge()>> | <<median,median()>> | | | <<vector-is-normalized,vectorisNormalized()>> | <<decode,decode()>>
| <<shortest-path-function,shortestPath()>> | <<percentile,percentile()>> | | | <<vector-has-nan,vectorHasNaN()>> | <<bool-and,bool_and()>>
| <<dijkstra,dijkstra()>> | <<random-int,randomInt()>> | | | <<vector-has-inf,vectorHasInf()>> | <<bool-or,bool_or()>>
| <<astar,astar()>> | | | | <<vector-dot-product,vectorDotProduct()>> | <<expand,expand()>>
| | | | | <<vector-magnitude,vectorMagnitude()>> | <<version,version()>>
| | | | | <<vector-l1-norm,vectorL1Norm()>> |
| | | | | <<vector-linf-norm,vectorLInfNorm()>> |
| | | | | <<vector-l2-distance,vectorL2Distance()>> |
| | | | | <<vector-cosine-similarity,vectorCosineSimilarity()>> |
Expand Down
8 changes: 6 additions & 2 deletions src/main/asciidoc/query-languages/sql/sql-create-index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE INDEX [<manual-index-name>]
[ IF NOT EXISTS ]
[ ON <type> (<property> [BY KEY|VALUE|ITEM][,]*) ]
<index-type> [<key-type>]
[ NULL_STRATEGY SKIP|ERROR]
[ NULL_STRATEGY SKIP|ERROR|INDEX]

----

Expand Down Expand Up @@ -59,7 +59,11 @@ In order to create an index, the schema must already exist in your database.
In the event that the `ON` and `&lt;key-type&gt;` clauses both exist, the database validates the specified property types.
If the property types don't equal those specified in the key type list, it throws an exception.

NOTE: Null values are not indexed, so any query that is looking for null values will not use the index with a full scan.
The `NULL_STRATEGY` determines how null values are indexed:

* `SKIP` (default) excludes null values from the index,
* `ERROR` throws an error in case a null value is found during indexing,
* `INDEX` adds null values to the index.

NOTE: A unique index does not regard derived types or embedded documents of the indexed type.

Expand Down
3 changes: 2 additions & 1 deletion src/main/asciidoc/query-languages/sql/sql-create-type.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Creates a new type in the schema.
----
CREATE <DOCUMENT|VERTEX|EDGE> TYPE <type>
[UNIDIRECTIONAL] [ IF NOT EXISTS ]
[EXTENDS <super-type>] [BUCKET <bucket-id>[,]*] [BUCKETS <total-bucket-number>]
[EXTENDS <super-type>] [BUCKET <bucket-id>[,]*] [BUCKETS <total-bucket-number>] [PAGESIZE <page-size>]

----

Expand All @@ -24,6 +24,7 @@ CREATE <DOCUMENT|VERTEX|EDGE> TYPE <type>
* *`&lt;super-type&gt;`* Defines the super-type you want to extend with this type.
* *`&lt;bucket-id&gt;`* Defines in a comma-separated list the ID's of the buckets you want this type to use.
* *`&lt;total-bucket-number&gt;`* Defines the total number of buckets you want to create for this type. The default value is `1`.
* *`&lt;page-size&gt;`* Defines the page size of the type.

In the event that a bucket of the same name exists in the bucket, the new type uses this bucket by default. If you do not define a
bucket in the command and a bucket of this name does not exist, ArcadeDB creates one. The new bucket has the same name as the type,
Expand Down
176 changes: 0 additions & 176 deletions src/main/asciidoc/query-languages/sql/sql-functions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -564,182 +564,6 @@ SELECT if( (name = 'John'), "My name is John", "My name is not John") FROM Perso

'''

[discrete]
[[case-expression]]
===== CASE Expression

NOTE: Available from version *26.2.1*

The `CASE` expression provides conditional logic similar to if-then-else statements in programming languages.
It supports two forms: **searched CASE** and **simple CASE**.

*Searched CASE Syntax*

Evaluates conditions sequentially and returns the result of the first matching condition:

[source,sql]
----
CASE
WHEN <condition1> THEN <result1>
WHEN <condition2> THEN <result2>
[ELSE <default_result>]
END
----

*Simple CASE Syntax*

Compares an expression against multiple values:

[source,sql]
----
CASE <expression>
WHEN <value1> THEN <result1>
WHEN <value2> THEN <result2>
[ELSE <default_result>]
END
----

*Behavior*

* The `CASE` expression evaluates conditions in order and returns the result of the first matching `WHEN` clause
* If no conditions match and an `ELSE` clause is provided, the `ELSE` result is returned
* If no conditions match and there is no `ELSE` clause, `null` is returned
* Multiple `WHEN` clauses can be specified
* Can be used in `SELECT` projections, `WHERE` clauses, `MATCH` statements, `LET` clauses, and expressions
* Supports nested `CASE` expressions for complex conditional logic
* `NULL` values in conditions follow SQL three-valued logic (NULL comparisons return NULL, which is treated as false)

*Examples*

Searched CASE with conditions in SELECT:

[source,sql]
----
SELECT
name,
CASE
WHEN age < 18 THEN 'Minor'
WHEN age >= 18 AND age < 65 THEN 'Adult'
ELSE 'Senior'
END as ageGroup
FROM Person
----

Simple CASE with value matching:

[source,sql]
----
SELECT
name,
CASE status
WHEN 'active' THEN 1
WHEN 'inactive' THEN 0
ELSE -1
END as statusCode
FROM Account
----

CASE without ELSE (returns null if no match):

[source,sql]
----
SELECT
name,
CASE
WHEN score > 90 THEN 'Excellent'
WHEN score > 75 THEN 'Good'
END as grade
FROM Student
----

CASE in WHERE clause for filtering:

[source,sql]
----
SELECT name, age
FROM Person
WHERE CASE
WHEN age IS NULL THEN false
WHEN age < 18 THEN 'minor'
ELSE 'adult'
END = 'adult'
----

CASE in MATCH WHERE clause (enum-to-string conversion with pattern matching):

[source,sql]
----
MATCH {type: Product, as: prod,
where: ((CASE
WHEN color = 1 THEN 'red'
WHEN color = 2 THEN 'blue'
WHEN color = 3 THEN 'green'
END) ILIKE '%ed%')}
RETURN prod.name
----

This is particularly useful for converting enum values (stored as integers) to human-readable strings that can be filtered with wildcards.

CASE in MATCH RETURN clause:

[source,sql]
----
MATCH {type: Person, as: p, where: (age IS NOT NULL)}
RETURN p.name,
CASE
WHEN p.age < 18 THEN 'minor'
WHEN p.age < 65 THEN 'adult'
ELSE 'senior'
END as category
ORDER BY p.name
----

Nested CASE expressions:

[source,sql]
----
SELECT
name,
CASE
WHEN balance > 0 THEN
CASE
WHEN balance > 10000 THEN 'Premium'
ELSE 'Standard'
END
ELSE 'Overdrawn'
END as accountStatus
FROM Account
----

CASE in LET clause:

[source,sql]
----
SELECT $category
FROM Product
LET $category = CASE
WHEN price < 10 THEN 'Budget'
WHEN price < 100 THEN 'Standard'
ELSE 'Premium'
END
----

CASE with NULL handling:

[source,sql]
----
SELECT
name,
CASE
WHEN age IS NULL THEN 'Unknown'
WHEN age < 18 THEN 'Minor'
ELSE 'Adult'
END as status
FROM Person
----

'''

[discrete]
[[ifempty-function]]
===== ifempty() [Function]
Expand Down
10 changes: 0 additions & 10 deletions src/main/asciidoc/query-languages/sql/sql-introduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,6 @@ Following are some basic differences between ArcadeDB and PostgreSQL.
| `SELECT * FROM pg_database` | `SELECT FROM schema:database`
|===











However, there is a SQL condition where the two systems do differ.
When you use functions that do not affect the column name, SQL defines that function name as the column name.
In ArcadeDB, since we're projecting from a record, the resulting name remains the property name.
Expand Down
Loading