0

I would like to be able to insert data into a MySQL database and have one or more of those columns the result of a MySQL function. For instance:

CREATE TABLE values (a varchar(255), b int, c date);
INSERT INTO table (a,b,c) values (null,2,NOW());

How do I do this in SQLAlchemy using the table metadata and db engine? Right now I create a dict of code called items and run:

connection.execute(table.insert().values(items))

But I don't know how to put NOW() into items.

Chris

1 Answer 1

1
ins = table.insert().values(a=None, b=2, c=func.now())
engine.execute(ins)
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thanks for the example it helped me uncover a little more of what SQLAlchemy is doing! docs.sqlalchemy.org/en/rel_0_7/core/tutorial.html#functions

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.