本文介绍了ScraperWiki:如何使用自动增量键创建和添加记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何使用代理键创建表吗?寻找像autoincrement这样的东西,只是一个大整数自动将下一个最高的唯一编号添加为主键.

Anyone know how to create a table with a surrogate key? looking forsomething like autoincrement, that is just a large integer thatautomatically adds the next highest unique number as the primary key.

需要知道如何创建表以及如何添加记录(最好通过scraperwiki.sqlite.save)

Need to know how to create the table as well as how to add records(preferably through scraperwiki.sqlite.save)

谢谢!

推荐答案

如果不回答更一般的一个 https://scraperwiki.com/scrapers/autoincr_demo

This seems to work for me for the specific case, if not answering themore general onehttps://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')

这篇关于ScraperWiki:如何使用自动增量键创建和添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:04