PostgreSQL, Hasura and citext data type

Today I started playing with Hasura and wanted to create a column to store an email address. Usually, I use varchar(255) (mostly because ORM generates it) but today I found out that citext can also be a good candidate. I want to treat emails as case-insensitive, [email protected] should be the same as [email protected].

The citext module provides a case-insensitive character string type, citext. Essentially, it internally calls lower when comparing values. Otherwise, it behaves almost exactly like text.

I wanted to create a column in Hasura console and it turned out that citext type is not available.

Hasura without citext

It's not an issue with Hasura! Hasura displays the types supported by the PostgreSQL database to which it is connected. I had to enable citext extension first.

How to do that?

Go to SQL and run the command below to create an extension.

CREATE EXTENSION IF NOT EXISTS citext;

You can also select This is a migration and Hasura can automatically create a migration file.

Hasura - SQL - citext extension

The citext type is available now!

Hasura with citext