Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've read that PostgreSQL can have "functional" indexes. For that you need the immutable keyword.

Seen that PostgreSQL is a CRUD DB I don't understand at all how it can possibly work in a functional way.

If there's an update or a delete to the DB, how can a past query guarantee that the result of the same query is always going to be the same?

share|improve this question
1  
the inclusion of a functional feature does not mean that the language is purely functional, nore does the primary paradigm being something else preclude a functional feature. –  xenoterracide Jan 11 '13 at 15:55
add comment

1 Answer 1

up vote 7 down vote accepted

I think you are getting confused with functional programming languages.

Anyway, a functional index is used to speed up access to data where queries that are accessing the data are using database functions.

By way of example, a query such as select blah from foo where sqrt(blah)=4 would have to perform the sqrt() operation for each value of blah. You could optimise this by pre-calculating all values of sqrt(blah) in a functional index: create index foo_func on foo (sqrt(blah));

This is where immutability comes in. A function is immutable if and only if the same input will always give the same output. Functional indexes can only use immutable functions. This guarantees that any queries for a given value and related functional index value will always return the same result.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.