Re: create index on a field of udt

From: "Charles Clavadetscher" <clavadetscher(at)swisspug(dot)org>
To: "'PostgreSQL mailing lists'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: create index on a field of udt
Date: 2015-06-29 07:41:01
Message-ID: 005901d0b23e$f6becbc0$e43c6340$@swisspug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

+1

create index on test (((i).id));

ANALYZE

explain select * from test where (i).id = 8909;

QUERY PLAN

-------------------------------------------------------------------------

Index Scan using test_id_idx on test (cost=0.43..8.45 rows=1 width=34)

Index Cond: ((i).id = 8909)

(2 rows)

From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Jeff Janes
Sent: Montag, 29. Juni 2015 08:42
To: Shujie Shang
Cc: John R Pierce; PostgreSQL mailing lists
Subject: Re: [GENERAL] create index on a field of udt

On Sun, Jun 28, 2015 at 10:31 PM, Shujie Shang <sshang(at)pivotal(dot)io <mailto:sshang(at)pivotal(dot)io> > 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 <http://i.id> )

It is a matter of finding the correct level of magic parentheses.

create index on test (((i).id));

The outer layer are always needed for creating indexes. The middle layer are needed because you are indexing an expression, not a column. And the inner layer is needed because, well, that is just how udt works.

Cheers,

Jeff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Xavier 12 2015-06-29 09:05:00 Re: pg_xlog on a hot_stanby slave
Previous Message Andy Erskine 2015-06-29 07:27:14 Re: Turn off streaming replication - leaving Master running