Hi,
On 23 Авг, 17:47, Michael Bayer <[EMAIL PROTECTED]> wrote:
> dont compile() the insert statement yourself here; since you are only
> executing it once, theres nothing to be gained by manually compiling
> first.
this was the minimal code demonstrating the issue.
i planned to do this many times for bulk insert into the table in
database-independent way.
> Its also the source of the error. the issue is that when the
> Insert is compiled with no "values" clause, it produces column
> entries for all three columns; but youre only sending two columns in
> your argument list. this behavior is the same in 0.3.
seems there is some other prob too:
- in 0.3 it is issued 2 statements:
select nextval('"Manager_id_seq"')
and then:
INSERT INTO "Manager" (duties, name, id) VALUES (%(duties)s, %(name)s,
%(id)s)
with the ids got from the db and the other parameters.
- in 0.4 it is issued only the last insert with all ids None which
leads to the error
>
> to compile the insert for just two columns (which again, you probably
> dont need to do here), put them in the "values" clause:
>
> c = Insert(values={'x':bindparam('x'), 'y':bindparam('y')}).compile()
> engine.execute(c, {'x':5, 'y':7})
>
even in this case the error is the same in 0.4:
2007-08-23 17:59:34,573 INFO sqlalchemy.engine.base.Engine.0x..2c
INSERT INTO "Manager" (duties, name, id) VALUES (%(duties)s, %(name)s,
%(id)s)
2007-08-23 17:59:34,573 INFO sqlalchemy.engine.base.Engine.0x..2c
[{'name': 'torencho', 'duties': 'bany', 'id': None}, {'name':
'mnogoVojdMalkoIndianec', 'duties': 'lany', 'id': None}]
2007-08-23 17:59:34,578 INFO sqlalchemy.engine.base.Engine.0x..2c
ROLLBACK
Traceback (most recent call last):
File "insertMultiple.py", line 46, in <module>
checkWith( db_postgres)
File "insertMultiple.py", line 40, in checkWith
dict( name= 'mnogoVojdMalkoIndianec', duties= 'lany'),
File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 784, in
execute
return Connection.executors[c](self, object, multiparams, params)
File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 815, in
_execute_clauseelement
return self._execute_compiled(elem.compile(dialect=self.dialect,
parameters=param), multiparams, params)
File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 826, in
_execute_compiled
self.__execute_raw(context)
File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 838, in
__execute_raw
self.__executemany(context)
File "/home/stefanb/src/hor/sqlalchemy/engine/base.py", line 872, in
__executemany
raise exceptions.SQLError(context.statement, context.parameters,
e)
sqlalchemy.exceptions.IntegrityError: (IntegrityError) null value in
column "id" violates not-null constraint
'INSERT INTO "Manager" (duties, name, id) VALUES (%(duties)s, %
(name)s, %(id)s)' [{'name': 'torencho', 'duties': 'bany', 'id': None},
{'name': 'mnogoVojdMalkoIndianec', 'duties': 'lany', 'id': None}]
regards,
stefan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---