Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql: ERROR: type "citext" does not exist

I have read other posts, when searching, an answer to this question.

I am using PostgreSQL 9.1, and created extension 'citext' using CREATE EXTENSION citext, but when I try to create any columns of type 'citext', it throws this error

ERROR: type "citext" does not exist

I researched but did not find any concrete answers? Any idea why?

like image 596
NullException Avatar asked Apr 12 '13 21:04

NullException


People also ask

What is Citext in PostgreSQL?

The citext data type allows you to eliminate calls to lower in SQL queries, and allows a primary key to be case-insensitive. citext is locale-aware, just like text , which means that the matching of upper case and lower case characters is dependent on the rules of the database's LC_CTYPE setting.

How do I use Citext in PostgreSQL?

To enable citext , just run something like this. CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public; To list all enabled extensions on your system, run the command \dx . Now you can change the column type to citext .

What are PostgreSQL extensions?

Extensions were implemented in PostgreSQL 9.1 to allow for easier packaging of additions to PostgreSQL. Extensions can package user-visible functions or use hooks in the PostgreSQL to modify how the database does certain processes.


2 Answers

Ok figured it out. I have several databases and CREATE EXTENSION citext has to be run for each db to install the extension in that DB. You must do on psql prompt:

psql =# \c db_1 CREATE EXTENSION citext;  psql =# \c db_2 CREATE EXTENSION citext; 

Hope it helps others. Thank you.

like image 79
NullException Avatar answered Oct 13 '22 05:10

NullException


@NullException is correct that the extension needs to be created in each database. If you want to automatically have an extension created, you can create it in the template1 database which (by default, at least) is the database used as a model for "create database", so with appropriate permissions, in psql:

\c template1 create extension citext; 

Then new databases will include citext by default.

like image 31
shaunc Avatar answered Oct 13 '22 04:10

shaunc