Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ngsQz-0006es-8r for pgsql-sql@arkaria.postgresql.org; Tue, 19 Apr 2022 18:18:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ngsQy-0001Im-33 for pgsql-sql@arkaria.postgresql.org; Tue, 19 Apr 2022 18:18:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ngsQx-0001Hf-OG for pgsql-sql@lists.postgresql.org; Tue, 19 Apr 2022 18:18:39 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ngsQv-0000jb-OD for pgsql-sql@lists.postgresql.org; Tue, 19 Apr 2022 18:18:39 +0000 Received: by mail-pf1-x430.google.com with SMTP id r10so5246581pfh.13 for ; Tue, 19 Apr 2022 11:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=htyleTm1FG5micQ/j2/ZuJSpbfCSAS4ARelAPZGVwdM=; b=JUyIrd7T6YrTWs/6zXIsGL3pSBuV6eW7m62/sKHtTvy8PZO/ll0UgHjJZSwskgmczo cVuEh85SHRYFyhbPgpWO1Pk7/PoeDjD30k2E3tewo7weh3tWVDaJni7X36NMk8ZGp28+ UzCA565TV6fCAAL7doh7qbdmKxlHLAFyQu3hn4+kl1tj27bVgjN5vTh+VJKoGpoUAAck saEFJ1yoksUOidZ7+Ozln57J/fmfmhq5NxYIKrTFpKbus1wV3bXLSVaL/v39bvXHG9Lt 9I4TJUwjVVRrjttgDqe8atwOpLvJCC18OmTQL3wIj0k/hlaliLrumOJID/MzYsbxvEIX ruAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=htyleTm1FG5micQ/j2/ZuJSpbfCSAS4ARelAPZGVwdM=; b=jQjie5CxACo6p5nCm2w9IV8zKK2uBV1aP6EaGe0TPPn0QdWcEQg+/frY7vHlFSBCm/ XLmbIeG8UHXDlp1j25cbP4TEyepm9upHkUMCO2z40xxGeH5MDnLmma9RD5PA49OUVJuh eAkSJPTg3DbH5XtUJAJMQvn6CPu/Cl/B39woAgI6V+UlB3wF7nhvB22gS/KiWclGZ0sD 9VJR/gQObgC7NwLfVcBGY9KqtZygEeXv/ZKPwIOjbm/brCP5oI/ssl0LSyoQ+wNbhGS3 02XrI7cBJdbeR1swkW2+d+m4Jl2LI9ElU5Vn9t1HthqTXc1yecveVx8SFJ7IKJEN+6hs 132A== X-Gm-Message-State: AOAM531FSfHqFQz1uz57Km9xFfOGVXwH7HIvmqb6jFNvICkSR4bA+vRu nfQL5dpiprADyypaJQYLV0UI3mYpbpM= X-Google-Smtp-Source: ABdhPJx8Rsr/iPfEG8M+ko4HfSEMvnfLjTjcYC2jA481NU/fHyNJ7gd7rPsYGOPXozkX+gfMHm/lQA== X-Received: by 2002:aa7:90d5:0:b0:4e1:307c:d94a with SMTP id k21-20020aa790d5000000b004e1307cd94amr18986752pfk.38.1650392314874; Tue, 19 Apr 2022 11:18:34 -0700 (PDT) Received: from [10.128.71.194] ([155.98.131.2]) by smtp.gmail.com with ESMTPSA id x22-20020aa784d6000000b005082b06cc58sm16386192pfn.215.2022.04.19.11.18.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Apr 2022 11:18:33 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------aZx8bDpG6NGTpj3eUVyK8FPb" Message-ID: <54858e28-402d-92fc-3c65-c9f82763112a@gmail.com> Date: Tue, 19 Apr 2022 12:18:32 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Create index on user defined type Content-Language: en-CA To: pgsql-sql@lists.postgresql.org References: <4D6ADD6D-0E11-4E6C-BF6D-AFB57FFF1B67@thebuild.com> From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------aZx8bDpG6NGTpj3eUVyK8FPb Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 4/19/22 11:03, aditya desai wrote: > Thanks! Apologies! Looks like I was having issues with NULL values and > UNIQUE index on user defined column. > > On Tue, Apr 19, 2022 at 10:00 PM Christophe Pettus > wrote: > > > > On Apr 19, 2022, at 09:27, aditya desai wrote: > > > > Hi, > > Is there any way to create index on user defined type in > Postgresql? Need to create index on bug_status in bug table. > > > > CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed'); > > > > CREATE TABLE bug ( > >     id serial, > >     description text, > >     status bug_status > > ); > > It works right out of the box: > > xof=# CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed'); > CREATE TYPE > xof=# CREATE TABLE bug ( >     id serial, >     description text, >     status bug_status > ); > CREATE TABLE > xof=# create index on bug(status); > CREATE INDEX > xof=# > I would have to wonder at the effectiveness an index on such a small number of possible values. --------------aZx8bDpG6NGTpj3eUVyK8FPb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 4/19/22 11:03, aditya desai wrote:
Thanks! Apologies! Looks like I was having issues with NULL values and UNIQUE index on user defined column.

On Tue, Apr 19, 2022 at 10:00 PM Christophe Pettus <xof@thebuild.com> wrote:

> On Apr 19, 2022, at 09:27, aditya desai <admad123@gmail.com> wrote:
>
> Hi,
> Is there any way to create index on user defined type in Postgresql? Need to create index on bug_status in bug table.
>
> CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');
>
> CREATE TABLE bug (
>     id serial,
>     description text,
>     status bug_status
> );

It works right out of the box:

xof=# CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');
CREATE TYPE
xof=# CREATE TABLE bug (
    id serial,
    description text,
    status bug_status
);
CREATE TABLE
xof=# create index on bug(status);
CREATE INDEX
xof=#

I would have to wonder at the effectiveness an index on such a small number of possible values.
--------------aZx8bDpG6NGTpj3eUVyK8FPb--