Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (27 sloc) 1.209 kB
layout: default
title: Insert: Adding a new entry to a database

Insert: Adding a new entry to a database

Problem: You want to add data to a database


With version 0.3, databases are defined like this:

db = web.database(dbn='postgres', db='mydata', user='dbuser', pw='')

Once the database is defined as such, performing insert can be performed like this:

# Insert an entry into table 'mytable'
sequence_id = db.insert('mytable', firstname="Bob",lastname="Smith",joindate=web.SQLLiteral("NOW()"))

The insert statement takes the following keyword arguments:

tablename seqname


The name of the table in your database to which you would like to add data to.


An optional argument, the default value is None. Set seqname to the ID if it's not the default, or to False.


The _test variable lets you see the SQL produced by the statement:

results ='mytable', offset=10, _test=True) 
><sql: 'SELECT * FROM mytable OFFSET 10'>


A set of named arguments that represent the fields in your table. If values are not given, the database may create default values or issue a warning.

Jump to Line
Something went wrong with that request. Please try again.