Scraperwiki: How To Create And Add Records With Autoincrement Key
Anyone know how to create a table with a surrogate key? looking for something like autoincrement, that is just a large integer that automatically adds the next highest unique numb
Solution 1:
This seems to work for me for the specific case, if not answering the more general one https://scraperwiki.com/scrapers/autoincr_demo
Bonuses include not having to specify the rest of the table at table creation :)
import scraperwiki
try:
scraperwiki.sqlite.execute("""
create table magic
(
id INTEGER PRIMARY KEY AUTOINCREMENT
)
""")
except:
print"Table probably already exists."
scraperwiki.sqlite.save(unique_keys=[], data={'payload':'fat beats'}, table_name='magic')
Post a Comment for "Scraperwiki: How To Create And Add Records With Autoincrement Key"