FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
FQL for SQL users
This section describes a number of common structured query language (SQL) queries and their Fauna Query Language (FQL) equivalents.
While it is almost impossible to provide an exhaustive comparison of every variation of all SQL commands, we provide a very basic comparison of the most used DDL (Data Definition Language) and DML (Data Manipulation Language) queries. As you gain more experience with the FQL, the ease and power of its syntax should become evident. Complex queries that are difficult, or even impossible, in SQL can be composed very easily in FQL. One very important difference between the two is that FQL is a functional language, while SQL is declarative. Hence, the actual path of execution must be provided for each FQL query. FQL requires the developer to specify an index in most queries.
SQL to FQL transpiler
If you’re familiar with SQL and want to ease into FQL, try out the SQL to FQL transpiler, created by Fauna Labs to help developers execute simple SQL statements on a Fauna database by translating them to FQL queries. This is not meant to be an exhaustive translation system between SQL and FQL, but it is a useful tool for you and your teams as you get started with FQL.
Conceptual equivalents
Relational | Fauna | Description |
---|---|---|
Table |
Tables store records, collections store documents. In a relational database, a table’s column definition specifies the structure for all records in the table. The column definition specifies the names and types of values that can be stored in a column. When visualized, the columns extend horizontally, and records are organized as rows that extend vertically, comprising a grid of values. Collections are merely a container for documents, imposing no specific structure on those documents. As such, there is no common way to visualize Fauna documents. |
|
Record / Row |
In a relational database, a record (or row) represents a distinct database entry. Every row must conform to the containing table’s column definition. Each Fauna document represents a nested structure of fields and their values, with no specified structure or types: each document, even in the same collection, can have its own independent structure. This makes Fauna documents schemaless. Additionally, each Fauna document is versioned, storing the history of a document’s mutations from creation to deletion. |
|
Schema |
For a relational database, a schema refers to the set of table definitions and constraints defined in that database. The schema is enforced so that no row violates its table definition or constraints. For Fauna, a database can contain Collections, Documents, User-defined functions, Indexes, security configuration such as Keys, Tokens, Credentials, Access Providers, and child databases (with arbitrarily deep nesting). A Fauna database contains schemaless documents with no schema enforcement available at the document level. |
|
Index / Materialized Views |
In a traditional relational database, an index is used as a performance optimization to help locate rows within tables without incurring the cost of a full table scan. A view is a virtual table whose contents are defined by a stored SQL query. |
|
Foreign Key |
Reference |
A foreign key is an identifier for a row in another table, which is (most often) protected by a constraint (an optional part of schema enforcement). The constraint causes errors if record modifications would damage the relation that a foreign key represents. Fauna has References, which can be used to uniquely identify a document anywhere in a particular database, but there are no built-in constraints protecting the relations. Due to Fauna’s schemaless nature, a Reference is not guaranteed to point at an existing document. |
In these examples below, we use two tables, dept
(departments) and
emp
(Employees) to compare basic operations in both query languages.
These tables have been extensively used in Oracle documentation to
explain various SQL basics.
SQL> DESC emp
Name Null? Type
----------------------------------------- --------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> DESC dept
Name Null? Type
----------------------------------------- --------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
ZIP NUMBER
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!