By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,692 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,692 IT Pros & Developers. It's quick & easy.

Functional index definition

P: n/a
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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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

Nov 12 '05 #2

P: n/a
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.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.