---
title: table.lookup
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/table/table-lookup
---

```
STRING table.lookup(ID id, STRING key, STRING default?)
```

**Available in:** all subroutines

Looks up the key `key` in the table `ID`. When the key is present, its
associated value will be returned. When the key is absent, a _not set_
string value is returned.

You can use `table.contains()` to check for the presence of a key.
If you plan to do a lookup of that key's value, consider combining
the calls into a single lookup to find the key's presence and the
stored value at the same time. For example:

```vcl
# note this depends on using a header, not a STRING variable
set req.http.x = table.lookup(t, "key");
if (!req.http.x) { # equivalent to if (!table.contains(t, "key"))
  # no such key
} else {
  # use the value of req.http.x
}
```

This works because a _not set_ header compares false in conditions.
The condition above depends on using a header for the returned value
and not a local STRING variable. This is because a _not set_ value
is converted to an empty string when assigned to a STRING variable
and the empty string always compares true in conditions.
See [VCL Types](https://www.fastly.com/documentation/reference/vcl/types/string/)
for details of the type conversion.

When a third STRING argument is provided, the lookup function behaves as
it would normally, except when a key is absent, the `default` value is
returned instead.

## Examples

```vcl
table geoip_lang {
  "US": "en-US",
  "FR": "fr-FR",
  "NL": "nl-NL",
}
if (!req.http.Accept-Language) {
  set req.http.Accept-Language = table.lookup(geoip_lang, client.geo.country_code, "en-US");
}
```

```vcl
table extension {
  "xhtml5": "xhtml",
  "html5": "html",
  "htm": "html",
  "aif": "aiff",
  "tif": "tiff",
  "jpg": "jpeg",
  "mpg": "mpeg",
}

sub vcl_recv {
  # normalizing URL file extensions
  declare local var.ext STRING;

  # lowercase for both the table key and for the default value
  set var.ext = std.tolower(req.url.ext);
  set var.ext = table.lookup(extension, var.ext, var.ext);
}
```
