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. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match