Em 22 de setembro de 2011 11:34, Leandro Guimarães Faria Corce DUTRA <[email protected]> escreveu: > Le 2011-S-22 11h25, Marcelo Silva (IG) a écrit : >> Eu precisava recuperar a sequencia da transacao naquele tabela > > Na tabela, tem de usar o MAX (), uma vez que a seqüência não é ligada à > tabela.
E duas transações concorrentes pegariam o mesmo valor então? Para isso que 'nextval' e 'setval' rodam atomicamente, mesmo que vários executem concorrentemente em múltiplas sessões [1]. Além do mais, ainda na documentação [1]: "Important: To avoid blocking concurrent transactions that obtain numbers from the same sequence, a nextval operation is never rolled back; that is, once a value has been fetched it is considered used, even if the transaction that did the nextval later aborts. This means that aborted transactions might leave unused "holes" in the sequence of assigned values. setval operations are never rolled back, either." Use o que o PostgreSQL te oferece: currval, lastval, setval e nextval. [1] http://www.postgresql.org/docs/current/static/functions-sequence.html -- Dickson S. Guedes mail/xmpp: [email protected] - skype: guediz http://guedesoft.net - http://www.postgresql.org.br _______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
