我使用'pg' gem来处理来自ruby的postgresql。插入新记录时,如何获取其序列号?
DB = PG.connect dbname: 'mydb', user: 'myuser'
res = DB.exec "insert into ..."
答案 0 :(得分:0)
我发现您可以将returning id
添加到查询字符串中。即。
DB = PG.connect dbname: 'mydb', user: 'myuser'
res = DB.exec "insert into ..."
id = res.first['id']