这个是PostgreSQL里的办法。<br><br><br>test=# create table test ( name varchar(4));<br>CREATE TABLE<br>test=# insert into test values ('b');<br>INSERT 0 1<br>test=# insert into test values ('c');<br>INSERT 0 1<br>test=# insert into test values ('d');
<br>INSERT 0 1<br>test=# insert into test values ('e');<br>INSERT 0 1<br>test=# insert into test values ('f');<br>INSERT 0 1<br>test=# select nextval('tablename_colname_seq') as line, name from test ;<br>&nbsp;line | name<br>------+------
<br>&nbsp;&nbsp;&nbsp; 2 | b<br>&nbsp;&nbsp;&nbsp; 3 | c<br>&nbsp;&nbsp;&nbsp; 4 | d<br>&nbsp;&nbsp;&nbsp; 5 | e<br>&nbsp;&nbsp;&nbsp; 6 | f<br>(5 行)<br><br>test=#<br><br>