- changed status to resolved
- changed component to documentation
Docs update for using functions with insert()
Issue #1791
resolved
I'm not a very good docs writer. However, here is my feeble attempt.
--- a/doc/build/sqlexpression.rst Wed Apr 28 16:58:23 2010 -0500
+++ b/doc/build/sqlexpression.rst Mon May 03 12:20:55 2010 -0500
@@ -136,6 +136,23 @@
>>> ins.compile().params #doctest: +NORMALIZE_WHITESPACE
{'fullname': 'Jack Jones', 'name': 'jack'}
+If you need to make use of SQL functions in your insert statements, you have to make use of the .values() functionality. For example, if you wanted to make use of the (contrived) UPPER function, you could do this:
+
+ >>> ins = users.insert().values( name=func.upper('jack'), fullname='Jack Jones')
+ >>> str(ins)
+ 'INSERT INTO users (name, fullname) VALUES (upper(:upper_1), :fullname)'
+
+Even if you don't normally use the .values functionality, to make use of functions you could take a hybrid approach. Making use of execution (see `Executing`_, below):
+
+ >>> conn = engine.connect()
+ >>> ins = users.insert().values( name=func.upper('jack') )
+ >>> conn.execute( ins, { fullname:'Jack Jones' } )
+ >>> r = conn.execute( ins, { 'fullname':'Jack Jones' } ) #doctest: +ELLIPSIS
+ {opensql}INSERT INTO users (name, fullname) VALUES (upper(?), ?)
+ ('jack', 'Jack Jones')
+ COMMIT
+ {stop}<sqlalchemy.engine.base.ResultProxy object at 0x...>
+
Comments (1)
-
repo owner - Log in to comment
that area of the documentation is only introducing the first SQL construct and hasn't covered SQL functions yet. Added some explanation of bindparam() and expressions such as func in conjunction with insert in the update section in d997bbaea827f5a14089ae42b5bd5d5e77589fd8.