Fm16 SQL Reference
Fm16 SQL Reference
SQL Reference
© 2013–2017 FileMaker, Inc. All Rights Reserved.
FileMaker, Inc.
5201 Patrick Henry Drive
Santa Clara, California 95054
FileMaker, FileMaker Go, and the file folder logo are trademarks of FileMaker, Inc. registered in the U.S. and other countries.
FileMaker WebDirect and FileMaker Cloud are trademarks of FileMaker, Inc. All other trademarks are the property of their respective
owners.
FileMaker documentation is copyrighted. You are not authorized to make additional copies or distribute this documentation without written
permission from FileMaker. You may use this documentation solely with a valid licensed copy of FileMaker software.
All persons, companies, email addresses, and URLs listed in the examples are purely fictitious and any resemblance to existing persons,
companies, email addresses, or URLs is purely coincidental. Credits are listed in the Acknowledgments documents provided with this
software. Mention of third-party products and URLs is for informational purposes only and constitutes neither an endorsement nor a
recommendation. FileMaker, Inc. assumes no responsibility with regard to the performance of these products.
For more information, visit our website at [Link]
Edition: 01
Contents
Chapter 1
Introduction 5
About this reference 5
About SQL 5
Using a FileMaker database as a data source 5
Using the ExecuteSQL function 6
Chapter 2
Supported standards 7
Support for Unicode characters 7
SQL statements 7
SELECT statement 8
SQL clauses 9
FROM clause 9
WHERE clause 11
GROUP BY clause 11
HAVING clause 12
UNION operator 12
ORDER BY clause 13
OFFSET and FETCH FIRST clauses 13
FOR UPDATE clause 14
DELETE statement 17
INSERT statement 17
UPDATE statement 19
CREATE TABLE statement 20
TRUNCATE TABLE statement 21
ALTER TABLE statement 22
CREATE INDEX statement 22
DROP INDEX statement 23
SQL expressions 23
Field names 23
Constants 23
Exponential/scientific notation 25
Numeric operators 25
Character operators 25
Date operators 25
Relational operators 26
Logical operators 27
Operator precedence 28
Contents 4
SQL functions 28
Aggregate functions 28
Functions that return character strings 30
Functions that return numbers 32
Functions that return dates 33
Conditional functions 34
FileMaker system objects 35
FileMaker system tables 35
FileMaker system columns 36
Reserved SQL keywords 37
Index 40
Chapter 1
Introduction
As a database developer, you can use FileMaker Pro to create database solutions without any
knowledge of SQL. But if you have some knowledge of SQL, you can use a FileMaker database
file as an ODBC or JDBC data source, sharing your data with other applications using ODBC and
JDBC. You can also use the FileMaker Pro ExecuteSQL function to retrieve data from any table
occurrence within a FileMaker Pro database.
This reference describes the SQL statements and standards supported by FileMaker. The
FileMaker ODBC and JDBC client drivers support all of the SQL statements described in this
reference. The FileMaker Pro ExecuteSQL function supports only the SELECT statement.
About SQL
SQL, or Structured Query Language, is a programming language that was designed to query data
from a relational database. The primary statement used to query a database is the SELECT
statement.
In addition to language for querying a database, SQL provides statements for performing data
manipulation, which allow you to add, update, and delete data.
SQL also provides statements for performing data definition. These statements allow you to create
and modify tables and indexes.
The SQL statements and standards supported by FileMaker are described in chapter 2,
“Supported standards.”
SQL statements
The ODBC and JDBC client drivers provide support for the following SQL statements:
1 SELECT (page 8)
1 DELETE (page 17)
1 INSERT (page 17)
1 UPDATE (page 19)
1 CREATE TABLE (page 20)
1 TRUNCATE TABLE (page 21)
1 ALTER TABLE (page 22)
1 CREATE INDEX (page 22)
1 DROP INDEX (page 23)
The client drivers also support FileMaker data type mapping to ODBC SQL and JDBC SQL data
types. See FileMaker ODBC and JDBC Guide for data type conversions. For more information on
constructing SQL queries, refer to a third-party book.
Note The ODBC and JDBC client drivers do not support FileMaker portals.
Chapter 2 | Supported standards 8
SELECT statement
Use the SELECT statement to specify which columns you're requesting. Follow the SELECT
statement with the column expressions (similar to field names) you want to retrieve (for example,
last_name). Expressions can include mathematical operations or string manipulation (for
example, SALARY * 1.05).
The SELECT statement can use a variety of clauses:
SELECT [DISTINCT] {* | column_expression [[AS] column_alias],...}
FROM table_name [table_alias], ...
[ WHERE expr1 rel_operator expr2 ]
[ GROUP BY {column_expression, ...} ]
[ HAVING expr1 rel_operator expr2 ]
[ UNION [ALL] (SELECT...) ]
[ ORDER BY {sort_expression [DESC | ASC]}, ... ]
[ OFFSET n {ROWS | ROW} ]
[ FETCH FIRST [ n [ PERCENT ] ] { ROWS | ROW } {ONLY | WITH TIES } ]
[ FOR UPDATE [OF {column_expression, ...}] ]
Items in brackets are optional.
column_alias can be used to give the column a more descriptive name, or to abbreviate a
longer column name.
Example
Field names can be prefixed with the table name or the table alias. For example, EMP.LAST_NAME
or E.LAST_NAME, where E is the alias for the table EMP.
The DISTINCT operator can precede the first column expression. This operator eliminates
duplicate rows from the result of a query.
Example
SQL clauses
The ODBC and JDBC client drivers provide support for the following SQL clauses.
Use this SQL clause To
FROM (page 9) Indicate which tables are used in the SELECT statement.
WHERE (page 11) Specify the conditions that records must meet to be retrieved (like a FileMaker Pro find
request).
GROUP BY (page 11) Specify the names of one or more fields by which the returned values should be grouped.
This clause is used to return a set of aggregate values by returning one row for each group
(like a FileMaker Pro subsummary).
HAVING (page 12) Specify conditions for groups of records (for example, display only the departments that
have salaries totaling more than $200,000).
UNION (page 12) Combine the results of two or more SELECT statements into a single result.
OFFSET (page 13) State the number of rows to be skipped before starting to retrieve rows.
FETCH FIRST (page 13) Specify the number of rows to be retrieved. No more than the specified number of rows are
returned although fewer rows may be returned if the query yields less than the number of
rows specified.
FOR UPDATE (page 14) Perform Positioned Updates or Positioned Deletes via SQL cursors.
Note If you attempt to retrieve data from a table with no columns, the SELECT statement returns
nothing.
FROM clause
The FROM clause indicates the tables that are used in the SELECT statement. The format is:
FROM table_name [table_alias] [, table_name [table_alias]]
table_name is the name of a table in the current database. The table name must begin with an
alphabetic character. If the table name begins with other than an alphabetic character, enclose it
in double quotation marks (quoted identifier).
table_alias can be used to give the table a more descriptive name, to abbreviate a longer table
name, or to include the same table in the query more than once (for example, in self-joins).
Field names begin with an alphabetic character. If the field name begins with other than an
alphabetic character, enclose it in double quotation marks (quoted identifier).
Example
Field names can be prefixed with the table name or the table alias.
Example
Given the table specification FROM employee E, you can refer to the LAST_NAME field as
E.LAST_NAME. Table aliases must be used if the SELECT statement joins a table to itself.
SELECT * FROM employee E, employee F WHERE E.manager_id = F.employee_id
The equal sign (=) includes only matching rows in the results.
If you are joining more than one table, and you want to discard all rows that don’t have
corresponding rows in both source tables, you can use INNER JOIN.
Example
SELECT *
FROM Salespeople INNER JOIN Sales_Data
ON Salespeople.Salesperson_ID = Sales_Data.Salesperson_ID
If you are joining two tables, but you don’t want to discard rows of the first table (the “left” table),
you can use LEFT OUTER JOIN.
Example
SELECT *
FROM Salespeople LEFT OUTER JOIN Sales_Data
ON Salespeople.Salesperson_ID = Sales_Data.Salesperson_ID
Every row from the “Salespeople” table will appear in the joined table.
Notes
1 RIGHT OUTER JOIN is not currently supported.
1 FULL OUTER JOIN is not currently supported.
Chapter 2 | Supported standards 11
WHERE clause
The WHERE clause specifies the conditions that records must meet to be retrieved. The WHERE
clause contains conditions in the form:
WHERE expr1 rel_operator expr2
expr1 and expr2 can be field names, constant values, or expressions.
rel_operator is the relational operator that links the two expressions.
Example
Note If you use fully qualified names in the SELECT (projection) list, you must also use fully
qualified names in the related WHERE clause.
GROUP BY clause
The GROUP BY clause specifies the names of one or more fields by which the returned values
should be grouped. This clause is used to return a set of aggregate values. It has the following
format:
GROUP BY columns
The scope of the GROUP BY clause is the table expression in the FROM clause. As a result, the
column expressions specified by columns must be from the tables specified in the FROM clause.
A column expression can be one or more field names of the database table separated by commas.
Example
HAVING clause
The HAVING clause enables you to specify conditions for groups of records (for example, display
only the departments that have salaries totaling more than $200,000). It has the following format:
HAVING expr1 rel_operator expr2
expr1 and expr2 can be field names, constant values, or expressions. These expressions do
not have to match a column expression in the SELECT clause.
rel_operator is the relational operator that links the two expressions.
Example
Return only the departments whose sums of salaries are greater than $200,000.
SELECT dept_id, SUM (salary) FROM emp
GROUP BY dept_id HAVING SUM (salary) > 200000
UNION operator
The UNION operator combines the results of two or more SELECT statements into a single result.
The single result is all of the returned records from the SELECT statements. By default, duplicate
records are not returned. To return duplicate records, use the ALL keyword (UNION ALL). The
format is:
SELECT statement UNION [ALL] SELECT statement
When using the UNION operator, the select lists for each SELECT statement must have the same
number of column expressions, with the same data types, and must be specified in the same
order.
Example
SELECT last_name, salary, hire_date FROM emp UNION SELECT name, pay,
birth_date FROM person
The following example is not valid because the data types of the column expressions are different
(SALARY from EMP has a different data type than LAST_NAME from RAISES). This example has
the same number of column expressions in each SELECT statement, but the expressions are not
in the same order by data type.
Example
SELECT last_name, salary FROM emp UNION SELECT salary, last_name FROM raises
Chapter 2 | Supported standards 13
ORDER BY clause
The ORDER BY clause indicates how the records are to be sorted. If your SELECT statement
doesn’t include an ORDER BY clause, the records may be returned in any order.
The format is:
ORDER BY {sort_expression [DESC | ASC]}, ...
sort_expression can be the field name or the positional number of the column expression to
use. The default is to perform an ascending (ASC) sort.
Examples
The second example uses the positional numbers 2 and 3 to get the same ordering as the
prior example that specified last_name and first_name explicitly.
SELECT emp_id, last_name, first_name FROM emp ORDER BY 2,3
Note FileMaker SQL uses the Unicode binary sort order, which is different from the
FileMaker Pro sort order used with language sorting or with the default language-neutral sort
order.
OFFSET format
The OFFSET format is:
OFFSET n {ROWS | ROW} ]
n is an unsigned integer. If n is larger than the number of rows returned in the result set, then
nothing is returned and no error message appears.
ROWS is the same as ROW.
Chapter 2 | Supported standards 14
Examples
Return information from the twenty-sixth row of the result set sorted by last_name then by
first_name.
SELECT emp_id, last_name, first_name FROM emp ORDER BY last_name, first_name
OFFSET 25 ROWS
Specify that you want to return only ten rows.
SELECT emp_id, last_name, first_name FROM emp ORDER BY last_name, first_name
OFFSET 25 ROWS FETCH FIRST 10 ROWS ONLY
Return the ten rows and their peer rows (rows that are not distinct based on the ORDER BY
clause).
SELECT emp_id, last_name, first_name FROM emp ORDER BY last_name, first_name
OFFSET 25 ROWS FETCH FIRST 10 ROWS WITH TIES
Example
Return all records in the employee database that have a SALARY field value of more than
$20,000.
SELECT * FROM emp WHERE salary > 20000
FOR UPDATE OF last_name, first_name, salary
When each record is fetched, it is locked. If the record is updated or deleted, the lock is held until
you commit the change. Otherwise, the lock is released when you fetch the next record.
Chapter 2 | Supported standards 15
Examples
Using Sample SQL
Retrieving the contents of a container field: CAST() function and GetAs() function
You can retrieve file reference information, binary data, or data of a specific file type from a
container field.
1 To retrieve file reference information from a container field, such as the file path to a file, picture,
or QuickTime movie, use the CAST() function with a SELECT statement.
1 If file data or JPEG binary data exists, the SELECT statement with GetAS(field name,
'JPEG') retrieves the data in binary form; otherwise, the SELECT statement with field name
returns NULL.
Example
Use the CAST() function with a SELECT statement to retrieve file reference information.
SELECT CAST(Company_Brochures AS VARCHAR) FROM Sales_Data
In this example, if you:
1 inserted a file into the container field using FileMaker Pro but stored only a reference to the
file, the SELECT statement retrieves the file reference information as type SQL_VARCHAR.
1 inserted the contents of a file into the container field using FileMaker Pro, the SELECT
statement retrieves the name of the file.
1 imported a file into the container field from another application, the SELECT statement
displays '?' (the file displays as [Link] in FileMaker Pro).
You can use the SELECT statement with the GetAs() function to retrieve the data in binary form
in the following ways:
1 When you use the GetAs() function with the DEFAULT option, you retrieve the master stream
for the container without the need to explicitly define the stream type.
Example
1 To retrieve an individual stream type from a container, use the GetAs() function with the file’s
type based on how the data was inserted into the container field in FileMaker Pro.
Example
If the data was inserted using the Insert > File command, specify 'FILE' in the GetAs() function.
SELECT GetAs(Company_Brochures, 'FILE') FROM Sales_Data
Example
If the data was inserted using the Insert > Picture command, drag and drop, or paste from the
clipboard, specify one of the file types listed in the following table, for example, 'JPEG'.
SELECT GetAs(Company_Logo, 'JPEG') FROM Company_Icons
Chapter 2 | Supported standards 17
DELETE statement
Use the DELETE statement to delete records from a database table. The format of the DELETE
statement is:
DELETE FROM table_name [ WHERE { conditions } ]
Note The WHERE clause determines which records are to be deleted. If you don’t include the
WHERE keyword, all records in the table are deleted (but the table is left intact).
Example
INSERT statement
Use the INSERT statement to create records in a database table. You can specify either:
1 A list of values to be inserted as a new record
1 A SELECT statement that copies data from another table to be inserted as a set of new records
Example
Note In container fields, you can INSERT text only, unless you prepare a parameterized
statement and stream the data from your application. To use binary data, you may simply assign
the filename by enclosing it in single quotation marks or use the PutAs() function. When
specifying the filename, the file type is deduced from the file extension:
Example
In this type of INSERT statement, the number of columns to be inserted must match the number
of columns in the SELECT statement. The list of columns to be inserted must correspond to the
columns in the SELECT statement just as it would to a list of value expressions in the other type
of INSERT statement. For example, the first column inserted corresponds to the first column
selected; the second inserted to the second, and so on.
The size and data type of these corresponding columns must be compatible. Each column in the
SELECT list should have a data type that the ODBC or JDBC client driver accepts on a regular
INSERT/UPDATE of the corresponding column in the INSERT list. Values are truncated when the
size of the value in the SELECT list column is greater than the size of the corresponding INSERT
list column.
The SELECT statement is evaluated before any values are inserted.
Chapter 2 | Supported standards 19
UPDATE statement
Use the UPDATE statement to change records in a database table. The format of the UPDATE
statement is:
UPDATE table_name SET column_name = expr, ... [ WHERE { conditions } ]
column_name is the name of a column whose value is to be changed. Several columns can be
changed in one statement.
expr is the new value for the column.
Usually the expressions are constant values for the columns (but they can also be a subquery).
You must enclose character string values in pairs of single quotation marks ('). To include a single
quotation mark in a character string value enclosed by single quotation marks, use two single
quotation marks together (for example, 'Don''t').
Subqueries must be enclosed in parentheses.
The WHERE clause is any valid clause. It determines which records are updated.
Example
Example
Note In container fields, you can UPDATE with text only, unless you prepare a parameterized
statement and stream the data from your application. To use binary data, you may simply assign
the filename by enclosing it in single quotation marks or use the PutAs() function. When
specifying the filename, the file type is deduced from the file extension:
Example
The CREATE TABLE statement for the field named _LASTNAME is:
CREATE TABLE "_EMPLOYEE" (ID INT PRIMARY KEY, "_FIRSTNAME" VARCHAR(20),
"_LASTNAME" VARCHAR(20))
1 For the CREATE TABLE statement repetitions, specify a field repetition by using a
number from 1 to 32000 in brackets after the field type.
Example
EMPLOYEE_ID INT[4]
LASTNAME VARCHAR(20)[4]
1 field_type may be any of the following: NUMERIC, DECIMAL, INT, DATE, TIME,
TIMESTAMP, VARCHAR, CHARACTER VARYING, BLOB, VARBINARY, LONGVARBINARY, or
BINARY VARYING. For NUMERIC and DECIMAL, you can specify the precision and scale.
For example: DECIMAL(10,0). For TIME and TIMESTAMP, you can specify the precision.
For example: TIMESTAMP(6). For VARCHAR and CHARACTER VARYING, you can specify
the length of the string.
Example
VARCHAR(255)
1 The DEFAULT keyword allows you to set a default value for a column. For expr, you may
use a constant value or expression. Allowable expressions are USER, USERNAME,
CURRENT_USER, CURRENT_DATE, CURDATE, CURRENT_TIME, CURTIME,
CURRENT_TIMESTAMP, CURTIMESTAMP, and NULL.
Chapter 2 | Supported standards 21
1 Defining a column to be UNIQUE automatically selects the Unique Validation Option for the
corresponding field in the FileMaker database file.
1 Defining a column to be NOT NULL automatically selects the Not Empty Validation Option
for the corresponding field in the FileMaker database file. The field is flagged as a Required
Value in the Fields tab of the Manage Database dialog box in FileMaker Pro.
1 To define a column as a container field, use BLOB, VARBINARY, or BINARY VARYING for
the field_type.
1 To define a column as a container field that stores data externally, use the EXTERNAL
keyword. The relative_path_string defines the folder where the data is stored
externally, relative to the location of the FileMaker database. This path must be specified as
the base directory in the FileMaker Pro Manage Containers dialog box. You must specify
either SECURE for secure storage or OPEN for open storage. If you are using open storage,
the calc_path_string is the folder inside the relative_path_string folder where
container objects are to be stored. The path must use forward slashes (/) in the folder name.
Examples
Using Sample SQL
text column CREATE TABLE T1 (C1 VARCHAR, C2 VARCHAR (50), C3 VARCHAR (1001),
C4 VARCHAR (500276))
text column, NOT NULL CREATE TABLE T1NN (C1 VARCHAR NOT NULL, C2 VARCHAR (50) NOT NULL,
C3 VARCHAR (1001) NOT NULL, C4 VARCHAR (500276) NOT NULL)
numeric column CREATE TABLE T2 (C1 DECIMAL, C2 DECIMAL (10,0), C3 DECIMAL
(7539,2), C4 DECIMAL (497925,301))
date column CREATE TABLE T3 (C1 DATE, C2 DATE, C3 DATE, C4 DATE)
column for container field CREATE TABLE T6 (C1 BLOB, C2 BLOB, C3 BLOB, C4 BLOB)
column for external storage CREATE TABLE T7 (C1 BLOB EXTERNAL 'Files/MyDatabase/' SECURE)
container field CREATE TABLE T8 (C1 BLOB EXTERNAL 'Files/MyDatabase/'
OPEN 'Objects')
Examples
To Sample SQL
set the default value for a ALTER TABLE Salespeople ALTER Company SET DEFAULT 'FileMaker'
column
remove the default value ALTER TABLE Salespeople ALTER Company DROP DEFAULT
for a column
Note SET DEFAULT and DROP DEFAULT do not affect existing rows in the table, but change the
default value for rows that are subsequently added to the table.
Example
Example
SQL expressions
Use expressions in WHERE, HAVING, and ORDER BY clauses of SELECT statements to form
detailed and sophisticated database queries. Valid expression elements are:
1 Field names
1 Constants
1 Exponential/scientific notation
1 Numeric operators
1 Character operators
1 Date operators
1 Relational operators
1 Logical operators
1 Functions
Field names
The most common expression is a simple field name, such as calc or
Sales_Data.Invoice_ID.
Constants
Constants are values that do not change. For example, in the expression PRICE * 1.05, the
value 1.05 is a constant. Or you might assign a value of 30 to the constant
Number_Of_Days_In_June.
You must enclose character constants in pairs of single quotation marks ('). To include a single
quotation mark in a character constant enclosed by single quotation marks, use two single
quotation marks together (for example, 'Don''t').
Chapter 2 | Supported standards 24
For ODBC and JDBC applications, FileMaker accepts the ODBC/JDBC format date, time, and
timestamp constants in braces ({}).
Examples
1 {D '2019-06-05'}
1 {T '14:35:10'}
1 {TS '2019-06-05 14:35:10'}
FileMaker allows the type specifier (D, T, TS) to be in upper case or lower case. You may use any
number of spaces after the type specifier, or even omit the space.
FileMaker also accepts SQL-92 syntax ISO date and time formats with no braces.
Examples
1 DATE 'YYYY-MM-DD'
1 TIME 'HH:MM:SS'
1 TIMESTAMP 'YYYY-MM-DD HH:MM:SS'
The FileMaker Pro ExecuteSQL function accepts only the SQL-92 syntax ISO date and time
formats with no braces.
Constant Acceptable syntax (examples)
Text 'Paris'
Number 1.05
When entering date and time values, match the format of the database file locale. For example, if
the database was created on an Italian language system, use Italian date and time formats.
Chapter 2 | Supported standards 25
Exponential/scientific notation
Numbers can be expressed using scientific notation.
Example
SELECT column1 / 3.4E+7 FROM table1 WHERE calc < 3.4E-6 * column2
Numeric operators
You can include the following operators in number expressions: +, -, *, /, and ^ or **
(exponentiation).
You can precede numeric expressions with a unary plus (+) or minus (-).
Character operators
You can concatenate characters. In the following, last_name is 'JONES ' and first_name is
'ROBERT '.
Operator Concatenation Example Result
+ Keep trailing blank characters first_name + last_name 'ROBERT JONES '
- Move trailing blank characters to the end first_name - last_name 'ROBERTJONES '
Date operators
You can modify dates. In the following, hire_date is DATE '2019-01-30'.
Operator Effect on date Example Result
+ Add a number of days to a date hire_date + 5 DATE '2019-02-04'
Addtional examples
Relational operators
Operator Meaning
= Equal
Example
Logical operators
You can combine two or more conditions. The conditions must be related by AND or OR, such as:
salary = 40000 AND exempt = 1
The logical NOT operator is used to reverse the meaning, such as:
NOT (salary = 40000 AND exempt = 1)
Example
Operator precedence
As expressions become more complex, the order in which the expressions are evaluated
becomes important. This table shows the order in which the operators are evaluated. The
operators in the first line are evaluated first, and so on. Operators in the same line are evaluated
left to right in the expression.
Precedence Operator
1 Unary '-', Unary '+'
2 ^, **
3 *, /
4 +, -
5 =, <>, <, <=, >, >=, Like, Not Like, Is Null, Is Not Null, Between, In, Exists, Any, All
6 Not
7 AND
8 OR
Examples
WHERE salary > 40000 OR hire_date > (DATE '2008-01-30') AND dept =
'D101'
Because AND is evaluated first, this query retrieves employees in department D101 hired
after January 30, 2008, as well as every employee making more than $40,000, no matter what
department or hire date.
To force the clause to be evaluated in a different order, use parentheses to enclose the
conditions to be evaluated first.
WHERE (salary > 40000 OR hire_date > DATE '2008-01-30') AND dept =
'D101'
This example retrieves employees in department D101 that either make more than $40,000
or were hired after January 30, 2008.
SQL functions
FileMaker SQL supports many functions you can use in expressions. Some of the functions return
characters strings, some return numbers, some return dates, and some return values that depend
on conditions met by the function arguments.
Aggregate functions
Aggregate functions return a single value from a set of records. You can use an aggregate function
as part of a SELECT statement, with a field name (for example, AVG(SALARY)), or in combination
with a column expression (for example, AVG(SALARY * 1.07)).
You can precede the column expression with the DISTINCT operator to eliminate duplicate
values.
Chapter 2 | Supported standards 29
Example
Example
You cannot use an aggregate function as an argument to other functions. If you do, FileMaker
returns the error code 8309 (“Expressions involving aggregations are not supported”). For
example, the following statement is not valid because the aggregate function SUM cannot be used
as an argument to the function ROUND:
Example
However, aggregate functions can use functions that return numbers as arguments. The following
statement is valid.
Example
RTRIM Removes trailing blanks from a string RTRIM(' ABC ') returns ' ABC'
TRIM Removes leading and trailing blanks from a TRIM(' ABC ') returns 'ABC'
string
LTRIM Removes leading blanks from a string LTRIM(' ABC') returns 'ABC'
TIME Returns the time of day as a string At 9:49 PM, TIME() returns 21:49:00
TIMEVAL
Note The TIME() function is deprecated. Use the SQL standard CURRENT_TIME instead.
Chapter 2 | Supported standards 31
Example
SELECT SUBSTR(Salespeople.Salesperson_ID, 2, 2) +
SUBSTR(Salespeople.Salesperson_ID, 4, 2) AS agg FROM Salespeople
SELECT SUBSTR(Salespeople.Salesperson_ID, 2) +
SUBSTR(Salespeople.Salesperson_ID, 4) AS agg FROM Salespeople
DAYOFWEEK Returns the day of week (1-7) of a date expression DAYOFWEEK(DATE '2004-05-01')
returns 7
MOD Divides two numbers and returns the remainder of the MOD(10,3) returns 1
division
NUMVAL Converts a character string to a number. The function NUMVAL('123') returns 123
fails If the character string is not a valid number.
Functions that
return numbers Description Example
SIGN An indicator of the sign of the argument: -1 for
negative, 0 for 0, and 1 for positive
Note The DATE() function is deprecated. Use the SQL standard CURRENT_DATE instead.
Chapter 2 | Supported standards 34
Conditional functions
Conditional
functions Description Example
CASE WHEN Simple CASE format SELECT
Invoice_ID,
Compares the value of input_exp to the values CASE Company_Name
of value_exp arguments to determine the result. WHEN 'Exports UK' THEN
'Exports UK Found'
CASE input_exp WHEN 'Home Furniture
{WHEN value_exp THEN result...} [ELSE Suppliers' THEN 'Home Furniture
result] Suppliers Found'
END ELSE 'Neither Exports UK
nor Home Furniture Suppliers'
END,
Salesperson_ID
FROM
Sales_Data
NULLIF Compares two values and returns NULL if the two SELECT
values are equal; otherwise, returns the first Invoice_ID,
value. NULLIF(Amount, -1),
Salesperson_ID
FROM
Sales_Data
Chapter 2 | Supported standards 35
FileMaker_Tables
The FileMaker_Tables table contains information about the database tables defined in the
FileMaker file.
The FileMaker_Tables table includes a row for each table occurrence in the relationships graph
with the following columns:
1 TableName - The name of the table occurrence.
1 TableId - The unique ID for the table occurrence.
1 BaseTableName - The name of the base table from which the table occurrence was created.
1 BaseFileName - The FileMaker filename for the database file that contains the base table.
1 ModCount - The total number of times changes to this table’s definition have been committed.
Example
FileMaker_Fields table
The FileMaker_Fields table contains information about the fields defined in the FileMaker file.
The FileMaker_Fields table includes the following columns:
1 TableName - The name of the table that contains the field.
1 FieldName - The name of the field.
1 FieldType - The SQL data type of the field.
1 FieldId - The unique ID for the field.
1 FieldClass - One of three values: Summary, for summary fields; Calculated, for calculated
results; or Normal.
1 FieldReps - The number of repetitions of the field.
1 ModCount - The total number of times changes to this table’s definition have been committed.
Example
ROWID column
The ROWID system column contains the unique ID number of the record. This is the same value
that the FileMaker Pro Get(RecordID) function returns.
ROWMODID column
The ROWMODID system column contains the total number of times changes to the current record
have been committed. This is the same value that the FileMaker Pro
Get(RecordModificationCount) function returns.
Example
Example
END_EXEC INTEGER OF
ESCAPE INTERSECT OFFSET
EVERY INTERVAL ON
EXCEPT INTO ONLY
EXCEPTION IS OPEN
EXEC ISOLATION OPTION
EXECUTE JOIN OR
EXISTS KEY ORDER
EXTERNAL LANGUAGE OUTER
EXTRACT LAST OUTPUT
FALSE LEADING OVERLAPS
FETCH LEFT PAD
FIRST LENGTH PART
FLOAT LEVEL PARTIAL
FOR LIKE PERCENT
FOREIGN LOCAL POSITION
FOUND LONGVARBINARY PRECISION
FROM LOWER PREPARE
FULL LTRIM PRESERVE
GET MATCH PRIMARY
GLOBAL MAX PRIOR
GO MIN PRIVILEGES
GOTO MINUTE PROCEDURE
GRANT MODULE PUBLIC
GROUP MONTH READ
HAVING MONTHNAME REAL
HOUR NAMES REFERENCES
IDENTITY NATIONAL RELATIVE
IMMEDIATE NATURAL RESTRICT
IN NCHAR REVOKE
INDEX NEXT RIGHT
INDICATOR NO ROLLBACK
INITIALLY NOT ROUND
INNER NULL ROW
INPUT NULLIF ROWID
INSENSITIVE NUMERIC ROWS
INSERT NUMVAL RTRIM
INT OCTET_LENGTH SCHEMA
Chapter 2 | Supported standards 39
SCROLL UNION
SECOND UNIQUE
SECTION UNKNOWN
SELECT UPDATE
SESSION UPPER
SESSION_USER USAGE
SET USER
SIZE USERNAME
SMALLINT USING
SOME VALUE
SPACE VALUES
SQL VARBINARY
SQLCODE VARCHAR
SQLERROR VARYING
SQLSTATE VIEW
STRVAL WHEN
SUBSTRING WHENEVER
SUM WHERE
SYSTEM_USER WITH
TABLE WORK
TEMPORARY WRITE
THEN YEAR
TIES ZONE
TIME
TIMESTAMP
TIMESTAMPVAL
TIMEVAL
TIMEZONE_HOUR
TIMEZONE_MINUTE
TO
TODAY
TRAILING
TRANSACTION
TRANSLATE
TRANSLATION
TRIM
TRUE
TRUNCATE
Index
A D
ABS function 32 date formats 24
aggregate functions in SQL 28 DATE function 33
ALL operator 26 date operators in SQL expressions 25
ALTER TABLE (SQL statement) 22 DATEVAL function 33
AND operator 27 DAY function 32
ANY operator 26 DAYNAME function 30
ATAN function 32 DAYOFWEEK function 32
ATAN2 function 32 DEFAULT (SQL clause) 20
DEG function 32
B DEGREES function 32
DELETE (SQL statement) 17
BaseFileName 35
DISTINCT operator 8
BaseTableName 35
DROP INDEX (SQL statement) 23
BETWEEN operator 26
binary data, use in SELECT 15
blank characters 25 E
blank value in columns 18 empty string, use in SELECT 15
BLOB data type, use in SELECT 15 ExecuteSQL function 6
EXISTS operator 26
C EXP function 32
exponential notation in SQL expressions 25
CASE WHEN function 34
expressions in SQL 23
CAST function 16
EXTERNAL (SQL clause) 21
CEIL function 32
CEILING function 32
character operators in SQL expressions 25 F
CHR function 30 FETCH FIRST (SQL clause) 14
COALESCE function 34 field names in SQL expressions 23
column aliases 8 field repetitions 17, 20
constants in SQL expressions 23 FieldClass 35
container field FieldId 35
stored externally 21 FieldName 35
with CREATE TABLE statement 21 FieldReps 35
with INSERT statement 18 FieldType 35
with PutAs function 18 FileMaker_Fields 35
with SELECT statement 16
FileMaker_Tables 35
with UPDATE statement 19
FLOOR function 32
CREATE INDEX (SQL statement) 22
FOR UPDATE (SQL clause) 14
CREATE TABLE (SQL statement) 20
FROM (SQL clause) 9
CURDATE function 33
FULL OUTER JOIN 10
CURRENT_DATE function 33
functions in SQL expressions 28
CURRENT_TIME function 33
CURRENT_TIMESTAMP function 33
CURRENT_USER function 30 G
cursors in ODBC 14 GetAs function 16
CURTIME function 33 GROUP BY (SQL clause) 11
CURTIMESTAMP function 33
H
HAVING (SQL clause) 12
HOUR function 32
Index 41
I O
IN operator 26 ODBC client driver
INNER JOIN 10 portals 7
INSERT (SQL statement) 17 Unicode support 7
INT function 32 ODBC standards compliance 7
IS NOT NULL operator 26 OFFSET (SQL clause) 13
IS NULL operator 26 operator precedence in SQL expressions 28
OR operator 27
J ORDER BY (SQL clause) 13
OUTER JOIN 10
JDBC client driver
portals 7
Unicode support 7 P
join 10 peer rows 14
PI function 32
K portals 7
positioned updates and deletes 14
keywords, reserved SQL 37
PREVENT INDEX CREATION 23
PutAs function 18, 19
L
LEFT function 30 R
LEFT OUTER JOIN 10
RADIANS function 32
LENGTH function 32
relational operators in SQL expressions 26
LIKE operator 26
reserved SQL keywords 37
LN function 32
RIGHT function 30
LOG function 32
RIGHT OUTER JOIN 10
logical operators in SQL expressions 27
ROUND function 32
LOWER function 30
ROWID system column 36
LTRIM function 30
ROWMODID system column 36
RTRIM function 30
M
MAX function 32 S
MIN function 32
scientific notation in SQL expressions 25
MINUTE function 32
SECOND function 32
MOD function 32
SELECT (SQL statement) 8
ModCount 35
binary data 15
MONTH function 32 BLOB data type 15
MONTHNAME function 30 empty string 15
SIGN function 33
N SIN function 33
NOT IN operator 26 sort order 13
NOT LIKE operator 26 SPACE function 30
NOT NULL (SQL clause) 21 SQL aggregate functions 28
NOT operator 27 SQL expressions 23
null value 18 character operators 25
constants 23
NULLIF function 34
date operators 25
numeric operators in SQL expressions 25
exponential or scientific notation 25
NUMVAL function 32 field names 23
functions 28
logical operators 27
numeric operators 25
operator precedence 28
relational operators 26
SQL standards compliance 7
Index 42
SQL statements
ALTER TABLE 22
CREATE INDEX 22
CREATE TABLE 20
DELETE 17
DROP INDEX 23
INSERT 17
reserved keywords 37
SELECT 8
supported by client drivers 7
TRUNCATE TABLE 21
UPDATE 19
SQL_C_WCHAR data type 7
SQL-92 7
SQRT function 33
standards compliance 7
string functions 30
STRVAL function 30
subqueries 17
SUBSTR function 30
SUBSTRING function 30
syntax errors 37
system tables 35
T
table aliases 8, 9
TableId 35
TableName 35
TAN function 33
time formats 24
TIME function 30
timestamp formats 24
TIMESTAMPVAL function 33
TIMEVAL function 30
TODAY function 33
TRIM function 30
TRUNCATE TABLE (SQL statement) 21
U
Unicode support 7
UNION (SQL operator) 12
UNIQUE (SQL clause) 21
UPDATE (SQL statement) 19
UPPER function 30
USERNAME function 30
V
VALUES (SQL clause) 17
W
WHERE (SQL clause) 11
WITH TIES (SQL clause) 14
Y
YEAR function 33