Re: create index on a field of udt - Mailing list pgsql-general

From Charles Clavadetscher
Subject Re: create index on a field of udt
Date
Msg-id 002801d0b230$8929d9a0$9b7d8ce0$@swisspug.org
Whole thread Raw
In response to Re: create index on a field of udt  (John R Pierce <pierce@hogranch.com>)
Responses Re: create index on a field of udt  (Shujie Shang <sshang@pivotal.io>)
List pgsql-general

Hello

 

I am not sure it is that simple. Probably you need to create operator classes to be used for indexing.

 

http://www.postgresql.org/docs/9.4/static/xtypes.html

 

You are probably better off using the basic data type in your table and using a composite index.

 

Bye

Charles

 

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of John R Pierce
Sent: Montag, 29. Juni 2015 07:51
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] create index on a field of udt

 

On 6/28/2015 10:31 PM, Shujie Shang wrote:

Oh, I didn't explain my question well, actually I want to create an index on an udt in a table.

 

e.g.

create type info as (id int, name text);

creat table test (i info);

I want to run:

create index myindex on test (i.id)


    create table test of info primary key(id);

or, if you want to use your type plus other stuff in the table, I believe its something like...

    create table test (i info, stuff...) primary key (i.id)
or
    create index test(i.id);


watch out for ambiguity if the type names match the table or field name.  see http://www.postgresql.org/docs/current/static/rowtypes.html#AEN7836


-- 
john r pierce, recycling bits in santa cruz

pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Turn off streaming replication - leaving Master running
Next
From: Andy Erskine
Date:
Subject: Re: Turn off streaming replication - leaving Master running