Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 August PostgreSQL: ERROR – data type character varying has no default operator class for access method “gist”

PostgreSQL: ERROR – data type character varying has no default operator class for access method “gist”

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

If we want to store range of data, we have very good options RANGE DATATYPE in PostgreSQL.

PostgreSQL: Example of RANGE Data Type

In one of our reporting servers, require to store a range of date bases on unique log code.
Means, one unique code cannot be duplicated with the same range of dates.

We can store a range of dates using TSRANGE DATATYPE, but I have to also add one constraint which checks the unique combination of value and range.

Here, I have taken an example of the Student table where the combination of Stud Name and Duration should be unique.
Try to Create below Student table:

1
2
3
4
5
6
7
CREATE TABLE tbl_Students
(
StudID INTEGER
,StudName CHARACTER VARYING
,Duration TSRANGE
,EXCLUDE USING GIST (StudName WITH=, Duration WITH &&)
);
While creating above table with EXCLUDE Range constraint,I was getting below error .
1
2
ERROR: data type character varying has no default operator class for access method "gist"
HINT: You must specify an operator class for the index or define a default operator class for the data
The solution is to create btree_gist EXTENSION.
1
CREATE EXTENSION btree_gist;
Insert few valid sample records:
1
2
3
4
5
6
INSERT INTO tbl_Students
VALUES
(1,'Anvesh','[2000-01-01, 2005-01-01)')
,(2,'Roy','[2001-01-01, 2006-01-01)')
,(3,'Eric','[2002-01-01, 2007-01-01)')
,(4,'Jenny','[2000-01-01, 2005-01-01)');
Try to Insert Same Student Name with same range:
1
2
3
INSERT INTO tbl_Students
VALUES
(5,'Anvesh','[2000-01-01, 2005-01-01)');
You will get an error like, because we have added constraint like, no duplicate range with the same Student Name.
1
ERROR: conflicting key value violates exclusion constraint "tbl_students_studname_duration_excl"
Aug 20, 2016Anvesh Patel
PostgreSQL: Example of RANGE Data TypePostgreSQL: Optimized way to populate new Column (UUID) in a Large Table
Comments: 4
  1. adarsh
    March 23, 2018 at 7:58 am

    Cool! Had the same error, got it fixed, thanks for the tip.

    • Anvesh Patel
      Anvesh Patel
      March 23, 2018 at 9:32 am

      thanks 🙂

  2. Frank
    March 29, 2018 at 10:10 am

    Thanks, had the same error.

  3. rolcs
    October 2, 2018 at 8:05 pm

    great work anvesh!

Anvesh Patel
Anvesh Patel

Database Engineer

August 20, 2016 PostgreSQLAnvesh Patel, btree_gist, database, database research and development, dbrnd, gist, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks, RANGE Datatype
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....