-
Notifications
You must be signed in to change notification settings - Fork 472
CITEXT data type #20028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
CITEXT data type #20028
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1885cd1
CITEXT data type
taroface a09973f
add callout
taroface 4ab784c
address reviewer comments; simplify doc
taroface 8095ac4
address review comments
taroface d4d2ca0
review edits
taroface 6c47f7e
Merge branch 'main' into citext-data-type
taroface b1885cb
Merge branch 'main' into citext-data-type
taroface 896784a
Merge branch 'main' into citext-data-type
taroface File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
title: CITEXT | ||
summary: The CITEXT data type stores case-insensitive text values. | ||
toc: true | ||
docs_area: reference.sql | ||
--- | ||
|
||
The `CITEXT` [data type]({% link {{ page.version.version }}/data-types.md %}) represents a case-insensitive string. Like `STRING` values, `CITEXT` values preserve their casing when stored and retrieved. Unlike `STRING` values, comparisons between `CITEXT` values are case-insensitive for all [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters) that have a defined uppercase/lowercase mapping (e.g., `'É' = 'é'`). | ||
|
||
Equality operators (`=`, `!=`, `<>`) and ordering operators (`<`, `>`, etc.) treat `CITEXT` values as case-insensitive by default. Refer to the [example](#example). | ||
|
||
{{site.data.alerts.callout_success}} | ||
`CITEXT` compares values as a `STRING` column with the `und-u-ks-level2` [collation]({% link {{ page.version.version }}/collate.md %}), meaning it is case-insensitive but accent-sensitive. | ||
{{site.data.alerts.end}} | ||
|
||
## Syntax | ||
|
||
To declare a `CITEXT` column, use the type name directly in your `CREATE TABLE` statement: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
CREATE TABLE logins ( | ||
name CITEXT PRIMARY KEY, | ||
email TEXT NOT NULL | ||
); | ||
~~~ | ||
|
||
## Size | ||
|
||
As with `STRING`, `CITEXT` values should be kept below 64 KB for best performance. Because `CITEXT` values resort to a collation engine on every comparison, `CITEXT` columns and indexes consume marginally more CPU and memory than their `STRING` equivalents. | ||
yuzefovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Example | ||
|
||
Create and populate a table: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
CREATE TABLE logins ( | ||
username CITEXT, | ||
email STRING | ||
); | ||
~~~ | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
INSERT INTO logins VALUES | ||
('Roach', 'Roach@example.com'), | ||
('lincoln', 'lincoln@example.com'); | ||
~~~ | ||
|
||
Because `CITEXT` comparisons are case-insensitive, an equality predicate matches regardless of letter case: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SELECT * FROM logins WHERE username = 'roach'; | ||
~~~ | ||
|
||
~~~ | ||
username | email | ||
-----------+-------------------- | ||
Roach | Roach@example.com | ||
(1 row) | ||
~~~ | ||
|
||
An ordering comparison is also case-insensitive with `CITEXT`: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SELECT username FROM logins WHERE username < 'Xavi'; | ||
~~~ | ||
|
||
~~~ | ||
username | ||
------------ | ||
Roach | ||
lincoln | ||
(2 rows) | ||
~~~ | ||
|
||
For case-sensitive comparisons on `CITEXT` values, cast to `STRING` explicitly. In the default Unicode ordering, an uppercase value is considered less than the lowercase value in the table: | ||
|
||
{% include_cached copy-clipboard.html %} | ||
~~~ sql | ||
SELECT username FROM logins WHERE username::STRING < 'Xavi'; | ||
~~~ | ||
|
||
~~~ | ||
username | ||
------------ | ||
Roach | ||
(1 row) | ||
~~~ | ||
|
||
## See also | ||
|
||
- [Data Types]({% link {{ page.version.version }}/data-types.md %}) | ||
- [`STRING`]({% link {{ page.version.version }}/string.md %}) | ||
- [`COLLATE`]({% link {{ page.version.version }}/collate.md %}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.