Functions and Operators
From Facebook Developers Wiki
In addition to the identifiers listed in the FQL Tables, FQL also supports some basic math and string manipulation. You can call these functions and use these operators anywhere that you could list one of the fields in the FQL Tables. You can use boolean comparison operators like =, >=, <, etc., parentheses for order of operations, and the arithmetic operators +, -, *, and /. The AND, OR, and NOT keywords are also supported. Finally, you can also call the following functions:
| Function | Description |
| now() | Returns the current time. |
| rand() | Generates a random number. |
| strlen(string) | Returns the length of the string. |
| concat(string, ...) | Concatenates the given strings (can take any number of strings). |
| substr(string, start, length) | Gets a substring of the string. |
| strpos(haystack, needle) | Returns the position of needle in haystack, or -1 if it is not found. |
| lower(string) | Converts the string to lower case. |
| upper(string) | Converts the string to upper case. |
Here's an example query that uses some of these:
| SELECT concat(first_name, substr(last_name, 0, 1), " is from ", upper(hometown_location.city), ", yo"), status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = [uid] ORDER BY rand() LIMIT 100) AND strlen(hometown_location.city) > 0 ORDER BY status.time DESC LIMIT 10 OFFSET 5 |
