CREATE INDEX question (how to index on "money" field?)

Started by Nonameover 22 years ago2 messagesgeneral
Jump to latest
#1Noname
charette@writeme.com

QUICK VERSION: How do I create an index on a field of type "MONEY"?

-----------------------------
LONG VERSION:

I have a table with a field of type "money". I very often need to
access records by the purchase price so I thought I'd create an index
to help out my selects:

CREATE INDEX purchasepriceidx ON mytable (purchaseprice);

This results in the following:

ERROR: data type money has no default operator class for access
method "btree" You must specify an operator class for the
index or define a default operator class for the data type

So if I understand this message correctly, it means that "money" has
no comparison operators associated with it? I RTFM'd and found the 51
available operators (SELECT am.amname AS acc_method, opc.opcname AS
ops_name FROM pg_am am, pg_opclass opc WHERE opc.opcamid = am.oid
ORDER BY acc_method, ops_name), but I don't see anything here that
seems to relate to "money" type fields. Am I correct about my
assuptions? Anyone have suggestions they can share? Any simple
examples posted anywhere?

PostgreSQL 7.3.4 on i586-pc-linux-gnu, compiled by GCC 2.96

Thanks,

Stephane Charette
stephanecharette @@@ telus ... net

#2Gaetano Mendola
mendola@bigfoot.com
In reply to: Noname (#1)
Re: CREATE INDEX question (how to index on "money" field?)

Stephane Charette wrote:

QUICK VERSION: How do I create an index on a field of type "MONEY"?

-----------------------------
LONG VERSION:

I have a table with a field of type "money". I very often need to
access records by the purchase price so I thought I'd create an index
to help out my selects:

CREATE INDEX purchasepriceidx ON mytable (purchaseprice);

It's working on 7.4:

Welcome to psql 7.4beta3, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

kalman=# create table test( a money );
CREATE TABLE
kalman=# create index idx on test (a );
CREATE INDEX

Regards
Gaetano Mendola