---
title: try_ip_host function
description: Learn the syntax of the try\_ip\_host function of the SQL language in Databricks Runtime.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/functions/try_ip_host
---

# `try_ip_host` function

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 18.2 and above

Returns the canonical representation of an IPv4 or IPv6 address. Returns `NULL` instead of raising an error if the input is invalid.

## Syntax

```
try_ip_host ( ip )
```

## Arguments

* `ip`: A `STRING` or `BINARY` value representing an IPv4 or IPv6 address.

## Returns

The same type as the input (`STRING` or `BINARY`), representing the canonical form of the address.

The function returns `NULL` if the input is `NULL` or invalid.

## Examples

```sql
> SELECT try_ip_host('192.168.1.5');
  192.168.1.5

> SELECT try_ip_host('2001:0db8:0000:0000:0000:0000:0000:0001');
  2001:db8::1

> SELECT try_ip_host('2001:DB8::1');
  2001:db8::1

> SELECT try_ip_host('::ffff:192.0.2.128');
  ::ffff:192.0.2.128

> SELECT hex(try_ip_host(X'C0A80101'));
  C0A80101

> SELECT try_ip_host('invalid');
  NULL

> SELECT try_ip_host(X'');
  NULL

> SELECT try_ip_host(NULL);
  NULL
```

## Related functions

* [`ip_host` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_host.md)
* [`try_ip_cidr` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/try_ip_cidr.md)
