May 17, 2020

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, user@example.com should be the same as UseR@example.com.

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

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.

The citext type is available now!

© 2020 Przemysław Kołodziejczyk