Functions and Operators
Problem
What functions and operators are supported in FQL?
Solution
FQL supports a number of functions that will be very familiar to PHP developers (see Table 8-1).
Table 8-1. FQL functions
Function | Description |
|---|---|
| Returns the current time |
| Generates a random number |
| Returns the length of the string |
| Concatenates strings together |
| Returns the specified substring |
| Returns the position of the needle in the haystack |
| Converts the string to lowercase |
| Converts the string to uppercase |
The standard set of SQL-like operators are supported: =, >=, <, etc., parentheses for order of operations, and the arithmetic operators +, -, *, and /. FQL also supports the AND, OR, and NOT logical operators inside of queries.
Discussion
You can use the functions directly inline with your FQL queries:
SELECT upper(concat(first_name, " ", substr(last_name, 0, 1), ".")), birthday FROM user WHERE sex = "female" AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $user) LIMIT 5;
That may not be the most practical query ever constructed, but
it will return user’s first five
female friends with their first name and last name’s first initial in
all caps. Do with it what you will.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access