ScraperWiki:如何使用自动增量键创建和添加记录 [英] ScraperWiki: How to create and add records with autoincrement key

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

问题描述

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

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 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 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')

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆