# Query String Parameters

Key: `container.key_value.query_string`

URL query string format: key1=value1\&key2=value2. Commonly found in URLs and HTTP POST bodies.

Page: <https://meridian.online/docs/finetype/types/container/key_value/query_string>

Samples: `name=John&age=30&city=NewYork`, `q=python&page=1`, `user_id=123&token=abc123xyz`

## Use it

Shell

```shell
finetype infer -i 'name=John&age=30&city=NewYork' --mode column
# → container.key_value.query_string
```

DuckDB

```sql
SELECT ft_infer('name=John&age=30&city=NewYork');
-- → 'container.key_value.query_string'
```

Cast template: {col} is your column

```sql
CAST({col} AS VARCHAR)
```

## Background

### Origin

RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, was published in January 2005 by T. Berners-Lee, R. Fielding and L. Masinter.[[1]](https://www.rfc-editor.org/rfc/rfc3986.txt) RFC 3986 defines the query component of a URI as the part indicated by the first question mark and terminated by a number sign or by the end of the URI.[[1]](https://www.rfc-editor.org/rfc/rfc3986.txt)

The WHATWG URL Standard now defines the application/x-www-form-urlencoded format as a way to encode a list of tuples, each consisting of a name and a value.[[2]](https://url.spec.whatwg.org/) The URL Standard calls the format in many ways an aberrant monstrosity, the result of many years of implementation accidents and compromises, and says it is in widespread use due to the prevalence of HTML forms.[[2]](https://url.spec.whatwg.org/)

### Use

A column of query strings in a data file is best read as a small record of named fields per row, flattened into one string. (Meridian's view) Splitting on \& and = by hand is tempting but fragile, so reach for a real form-urlencoded parser and keep the raw string alongside the parsed fields. (Meridian's view)

The URL Standard's parser replaces any + in names and values with a space before percent-decoding them as UTF-8.[[2]](https://url.spec.whatwg.org/) The URL Standard says only UTF-8 is conforming, though a legacy server-oriented implementation might have to support other encodings.[[2]](https://url.spec.whatwg.org/)

Python's parse\_qs ignores blank values by default unless keep\_blank\_values is set to a true value.[[3]](https://docs.python.org/3/library/urllib.parse.html)

RFC 1866 notes that because \& also begins an SGML entity reference, a URI such as http://host/?x=1\&y=2 must be written with \&\#38; or \&amp; inside an HTML attribute.[[4]](https://www.rfc-editor.org/rfc/rfc1866.txt)

## Sources

1. [Uniform Resource Identifier (URI): Generic Syntax](https://www.rfc-editor.org/rfc/rfc3986.txt) — standard
2. [URL Standard](https://url.spec.whatwg.org/) — standard
3. [urllib.parse — Parse URLs into components](https://docs.python.org/3/library/urllib.parse.html) — documentation
4. [Hypertext Markup Language - 2.0](https://www.rfc-editor.org/rfc/rfc1866.txt) — standard

## How it's detected

URL query string format. Values are typically URL-encoded. Recursive inference parses key-value pairs and types each value independently. The WHATWG URL Standard allows bare names and empty sequences beside pairs; at least one name=value pair is required here, so a column of bare names is not a query string. A sequence of only name=value pairs keeps the looser reading (any name text); once a bare name or an empty sequence appears, names may not hold whitespace and a value may not start with \`=\`, so expression text such as \`a == 1 \&\& b == 2\` is not a query string.
