Having previously asked [a question][1] on the limitations of *polymorph any object* myself, I feel quite confident in saying **it would last forever.**

A huge rock is undoubtedly part of the [mineral kingdom][2]; Whether water is a mineral is a little more debatable, but assuming it's as pure as you say, it's definitely not animal or vegetable. That gets us the Same Kingdom bonus of **+5**. The two objects are certainly not the Same Class, and not really Related, but it's trivial to make it the Same Size for another **+2**. Finally, while water is arguably slightly more intelligent than rock, I'd argue the difference is small enough to not show up at the granularity of ability scores used by D&D, so we can easily claim the **+2** Same or Lower Intelligence bonus.

**Adding all those up, we have a nice +9, for a Permanent duration.**

**That said, I should point out two things. First, for your use-case, the water doesn't need to be pure.** You're not transmuting the "element of the water" in your starting object into the "element of stone"; You're polymorphing "a barrel of water" into "a barrel-sized rock." You could similarly use *Polymorph Any Object* to turn "a corpse filled with daggers" into "a pure spherical crystal" and the resulting object would be entirely dagger-free; Impurities in the starting object don't have to be present in the end product if you don't want them to be.

**Second, there's some controversy and debate about what happens when you cast a spell to change an object into something else on a target that's already the subject of such a spell,** and *polymorph any object* is at the centre of that controversy. Its description says "The duration of the spell depends on how radical a change is made from the original state to its transmuted state," but it's not really clear whether the "original" state of the target should include changes made by previous polymorph spells. If you turn some water into a rock, and then cast *polymorph any object* again to turn the rock *into an identical rock*, how long does the spell last? Being able to make any *polymorph any object* spell permanent just by casting it twice seems like it might not be what the designers intended - and indeed, the section on the "polymorph" subschool does say "You can only be affected by one polymorph spell at a time."

On the other hand, *stone to flesh* isn't a polymorph spell even if it feels like one, and almost that entire section is written as if polymorph spells always target the caster and not inanimate objects, so it's still a little ambiguous what happens when you try to turn a rock-that-was-once-water into meat.

In any case, *polymorph any object* is arguably the ultimate polymorph spell: It can change almost anything into anything and do things that no other option in the rules can achieve, such as turning something that lacks a soul into something that has one. Many GMs will have different ideas about what it should and shouldn't be able to do and what the consequences of layering it with other spells should be, so I suspect you'll have to ask yours for a ruling.

  [1]: http://rpg.stackexchange.com/questions/16325/how-worldly-is-a-polymorphic-elf
  [2]: https://en.wikipedia.org/wiki/Linnaean_taxonomy#Classification_for_minerals

Thanks to the dark wanderer for the background on Linnaean taxonomy.