DBAPI勉強中(2)
色んなデータ型を試してみます。
import psycopg2 con = psycopg2.connect("dbname=testdb") cur = con.cursor() cur.execute("drop table if exists t") cur.execute(""" create table t( i integer, r real, n numeric, v varchar(10), t text, d date, ti time, ts timestamp) """) cur.execute(""" insert into t values( 1, 1.2, 2.2, 'hello', 'world', current_date, current_time, current_timestamp) """) cur.execute("select * from t") print cur.next()
結果。
(1, 1.2, Decimal("2.2"), 'hello', 'world', datetime.date(2008, 3, 31), datetime. time(17, 40, 34, 640000), datetime.datetime(2008, 3, 31, 17, 40, 34, 640000))
いい感じでキャストされてます。