Do you suggest to use server_default instead of DefaultClause in all cases? j Il giorno giovedì 8 gennaio 2015 15:17:20 UTC+1, Michael Bayer ha scritto: > > use server_default with text() as documented at > http://docs.sqlalchemy.org/en/rel_0_9/core/defaults.html#server-side-defaults. > > > > > > jo <jose....@sferacarta.com <javascript:>> wrote: > > > Hi all, > > > > I have a problem with DefautClause. I need to assign a default to a > numeric column. > > tbl['rischio_attivita'] = Table('rischio_attivita', database.metadata, > > Column('id', Integer, Sequence('rischio_attivita_seq'), > primary_key=True), > > Column('cod_attivita', Unicode(10),nullable=False), > > Column('cod_caratteristica_rischio', Unicode(10), nullable=False), > > Column('tipo_calcolo', Integer), > > Column('algoritmo', Unicode(200)), > > Column('fattore_x', Numeric(4,2), DefaultClause(1.0)), > > ForeignKeyConstraint(['cod_attivita'], ['attivita.codice']), > > ForeignKeyConstraint(['cod_caratteristica_rischio'], > ['caratteristica_rischio.codice']) > > ) > > > > > > I tried to assign a float to it and I got this error: > > > > File > "/home/sfera/sicer2/buildout/eggs/SQLAlchemy-0.9.3-py2.6-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", > > line 999, in assert_arg_type > > (name, ' or '.join("'%s'" % a for a in argtype), type(arg))) > > sqlalchemy.exc.ArgumentError: Argument 'arg' is expected to be one of > type '<type 'basestring'>' or '<class > 'sqlalchemy.sql.elements.ClauseElement'>' or '<class > 'sqlalchemy.sql.elements.TextClause'>', got '<type 'float'>' > > [sfera@tstsferagamma01 release]$ vi sicer/BASE/model/sql.py > > > > then I changed it to a string as in: > > Column('fattore_x', Numeric(4,2), DefaultClause('1.0')), > > and now I have this: > > > > sqlalchemy.exc.DatabaseError: (DatabaseError) ORA-01722: invalid number > > "\nCREATE TABLE attivita (\n\tid INTEGER NOT NULL, \n\tcod_attivita > NVARCHAR2(10) NOT NULL, \n\tcod_caratteristica_rischio NVARCHAR2(10) NOT > NULL, \n\ttipo_calcolo INTEGER, \n\talgoritmo NVARCHAR2(200), \n\tfattore_x > NUMERIC(4, 2) DEFAULT '1.0', \n\tPRIMARY KEY (id), \n\tFOREIGN > KEY(cod_attivita) REFERENCES attivita (codice), \n\tFOREIGN > KEY(cod_caratteristica_rischio) REFERENCES caratteristica_rischio > (codice)\n)\n\n" {} > > > > > > > > Is there another way to define a default clause? > > thanks. > > > > j > > > > -- > > You received this message because you are subscribed to the Google > Groups "sqlalchemy" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to sqlalchemy+...@googlegroups.com <javascript:>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > > Visit this group at http://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. >
-- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.