On Sat, Jan 15, 2005 at 01:27:49PM -0500, Tom Lane wrote: > Bo Lorentsen <bl@xxxxxxxxxxx> writes: > > select * from sale where id = currval( 'sale_id_seq' ); > > This is not legally optimizable into an indexscan, because currval() is > a volatile function. (It's easy to construct cases where its value > actually does change from row to row --- just use a nextval() as well.) > > You can fake it out in a couple of ways --- the recommended method is to > wrap currval in a user-defined function that is misleadingly marked > stable. I think it still works to just put the call in a sub-select: > select * from sale where id = (select currval( 'sale_id_seq' )); > but I take no responsibility if future improvements in the planner break > that trick. Would it make sense to have a version of currval that will only return one value in a statement/transaction? So the first time it's called it remembers what currval for that sequence is and always returns the same value? -- Jim C. Nasby, Database Consultant decibel@xxxxxxxxxxx Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html