SEARCH_IP
functionsupportedCore SQL functionsSearches for valid IPv4 and IPv6 addresses in specified character-string columns from one or more tables, including fields in VARIANT, OBJECT, and ARRAY columns. The search is based on a single IP address or a range of IP addresses that you specify. If an IP address in the column or field matches a specified IP address or is in a specified range, then the function returns TRUE. For more information about using this function, see Using full-text search.
Syntax
SEARCH_IP( <search_data>, '<search_string>' )
Parameters
| Name | Required | Description |
|---|---|---|
search_data | required | The data you want to search, expressed as a comma-delimited list of string literals, column names, or paths to fields in VARIANT columns. The search data can also be a single literal string, which can be useful when you are testing the function. You can specify the wildcard character (*), where * expands to all qualifying columns in all of the tables that are in scope for the function. Qualifying columns are those that have VARCHAR (text), VARIANT, ARRAY, and OBJECT data types. VARIANT, ARRAY, and OBJECT data is converted to text for searching. You can also use the ILIKE and EXCLUDE keywords for filtering. For more information about this argument, see the search_data description for the SEARCH function. |
'search_string' | required | A VARCHAR string that contains one of the following addresses: A complete and valid IP address in standard IPv4 or IPv6 format, such as 192.0.2.1 or 2001:0db8:85a3:0000:0000:8a2e:0370:7334. A valid IP address in standard IPv4 or IPv6 format with a Classless Inter-Domain Routing (CIDR) range, such as 192.0.2.1/24 or 2001:db8:85a3::/64. A valid IP address in standard IPv4 or IPv6 format with leading zeros, such as 192.000.002.001 instead of 192.0.2.1 or 2001:0db8:85a3:0333:4444:8a2e:0370:7334 instead of 2001:db8:85a3:333:4444:8a2e:370:7334. The function accepts up to three digits for each part of an IPv4 address, and up to four digits for each part of an IPv6 address. A valid compressed IPv6 address, such as 2001:db8:85a3:0:0:0:0:0 or 2001:db8:85a3:: instead of 2001:db8:85a3:0000:0000:0000:0000:0000. An IPv6 dual address that combines an IPv6 and an IPv4 address, such as 2001:db8:85a3::192.0.2.1. This argument must be a literal string. Specify one pair of single quotes around the string. The following types of arguments aren’t supported: Column names Empty strings More than one IP address Partial IPv4 and IPv6 addresses |
Returns
Returns a BOOLEAN: - Returns TRUE if a valid IP address is specified in search_string and a matching IP address is found in search_data. - Returns TRUE if a valid IP address with a CIDR range is specified in search_string and an IP address in the specified range is found in search_data. - Returns NULL if either of these arguments is NULL. - Otherwise, returns FALSE.
Usage notes
- The SEARCH_IP function operates only on VARCHAR (text), VARIANT, ARRAY, and OBJECT data. The function returns an error if the search_data argument doesn’t contain data of these data types. When the search_data argument includes data of both supported data types and unsupported data types, the function searches the data of the supported data types and silently ignores the data of the unsupported data types. For examples, see Examples of expected error cases.
- The function returns an error if the search_string argument isn’t a valid IP address. For examples, see Examples of expected error cases.
- You can add a FULL_TEXT search optimization on columns that are the target of SEARCH_IP function calls by using an ALTER TABLE command that specifies the ENTITY_ANALYZER. For example: Copy code ALTER TABLE ipt ADD SEARCH OPTIMIZATION ON FULL_TEXT( ipv4_source, ANALYZER => 'ENTITY_ANALYZER'); The ENTITY_ANALYZER recognizes only the entities (for example, IP addresses). Therefore, the search access path is typically much smaller than FULL_TEXT search optimization with a different analyzer. For more information, see enable FULL_TEXT search optimization.