[Sqlalchemy-tickets] Issue #3316: Default value doesn't work in SQLAlchemy + PostgreSQL (zzzeek/sql
Brought to you by:
zzzeek
|
From: Ander U. <iss...@bi...> - 2015-03-06 14:47:46
|
New issue 3316: Default value doesn't work in SQLAlchemy + PostgreSQL https://bitbucket.org/zzzeek/sqlalchemy/issue/3316/default-value-doesnt-work-in-sqlalchemy Ander Ustarroz: I've found an unexpected behavior in SQLAlchemy. I'm using the following versions: * SQLAlchemy (0.9.8) * psycopg2 (2.5.4) * PostgreSQL (9.3.5) This is the table definition for the example: ``` #!python from sqlalchemy import ( MetaData, Column, Integer, Table, String, ) metadata = Metadata() users = Table('users', metadata, Column('id_user', Integer, primary_key=True, nullable=False), Column('name', String(20), unique=True), Column('age', Integer, nullable=False, default=0), ) ``` If now I try to execute a simple insert to the table just populating the **id_user** and **name**, the column **age** should be auto-generated right? Lets see... ``` #!python data = {'id_user':1, 'name':'Jimmy' } stmt = users.insert().values(data) ``` This is the resulting statement: ``` #!sql INSERT INTO users (id_user, name, age) VALUES (1, 'Jimmy', null); ``` But the **age** column was not provided, where is that null coming from? I was expecting this: ``` #!sql INSERT INTO users (id_user, name) VALUES (1, 'Jimmy'); ``` Or if the ***default*** flag actually works should be: ``` #!sql INSERT INTO users (id_user, name, Age) VALUES (1, 'Jimmy', 0); ``` Could you put some light on this? |