Functional index definition

Started by Josué Maldonadoover 22 years ago3 messagesgeneral
Jump to latest
#1Josué Maldonado
josue@lamundial.hn

Hello list,

Is there a way to create indexes using functions like these:
substring(prod_no,8,4)
to_char(fkardex,'YYYYMM')
substr(facnum,1,2)

Help says is not possible but I would like to know if someone know an
undocumented/tricky way to get that done.

Thanks in advance

--
Josu� Maldonado.

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Josué Maldonado (#1)
Re: Functional index definition

On Tue, 11 Nov 2003, [ISO-8859-1] Josué Maldonado wrote:

Hello list,

Is there a way to create indexes using functions like these:
substring(prod_no,8,4)
to_char(fkardex,'YYYYMM')
substr(facnum,1,2)

Help says is not possible but I would like to know if someone know an
undocumented/tricky way to get that done.

Not directly in 7.3 and earlier. You have to make a function that wraps
the function you want to call with static arguments like:

create function substring_8_4(text) returns text as
'select substring($1, 8, 4);' language 'sql' immutable;

In 7.4, the indexes have been approved to allow indexes on expressions
which allow the above (with an extra set of parens in the definition).

#3Josué Maldonado
josue@lamundial.hn
In reply to: Stephan Szabo (#2)
Re: Functional index definition

Stephan Szabo wrote:
Thanks Stephan.

I forgot to say I'm using 7.3.4, your solutions worked fine.

On Tue, 11 Nov 2003, [ISO-8859-1] Josu� Maldonado wrote:

Hello list,

Is there a way to create indexes using functions like these:
substring(prod_no,8,4)
to_char(fkardex,'YYYYMM')
substr(facnum,1,2)

Help says is not possible but I would like to know if someone know an
undocumented/tricky way to get that done.

Not directly in 7.3 and earlier. You have to make a function that wraps
the function you want to call with static arguments like:

create function substring_8_4(text) returns text as
'select substring($1, 8, 4);' language 'sql' immutable;

In 7.4, the indexes have been approved to allow indexes on expressions
which allow the above (with an extra set of parens in the definition).

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

--
Josu� Maldonado.