<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">func.max and func.min do not convert result object to correct datetime object.</p>
<p dir="auto">---<a href="testcase.py">testcase.py</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sqlalchemy as sqa
import datetime


db = sqa.create_engine(&quot;sqlite://&quot;)
metadata = sqa.BoundMetaData(db)

#metadata.engine.echo = True # debug output

events_table = sqa.Table('events', metadata,
  sqa.Column('id', sqa.Integer, primary_key=True),
  sqa.Column('name', sqa.String(255)),
  sqa.Column('datetime', sqa.DateTime),
)
events_table.create()

i = events_table.insert()
name = &quot;just-a-name&quot;
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 10, 23, 44))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 12, 43, 44))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 17, 23, 34))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 22, 54, 23))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 23, 00, 18))


date = &quot;2007-07-26&quot;
test1 = sqa.select(
           [events_table.c.datetime](events_table.c.datetime),
           (sqa.func.date(events_table.c.datetime) == date) &amp;
           (events_table.c.name == name)
         ).execute().fetchone()
print &quot;--&quot;
print test1
print type(test1)
print type(test1[0](0))
print &quot;-&quot;
test2 = sqa.select(
           [sqa.func.max(events_table.c.datetime)](sqa.func.max(events_table.c.datetime)),
           (sqa.func.date(events_table.c.datetime) == date) &amp;
           (events_table.c.name == name)
         ).execute().fetchone()
print test2
print type(test2)
print type(test2[0](0))"><pre class="notranslate"><code class="notranslate">import sqlalchemy as sqa
import datetime


db = sqa.create_engine("sqlite://")
metadata = sqa.BoundMetaData(db)

#metadata.engine.echo = True # debug output

events_table = sqa.Table('events', metadata,
  sqa.Column('id', sqa.Integer, primary_key=True),
  sqa.Column('name', sqa.String(255)),
  sqa.Column('datetime', sqa.DateTime),
)
events_table.create()

i = events_table.insert()
name = "just-a-name"
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 10, 23, 44))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 12, 43, 44))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 17, 23, 34))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 22, 54, 23))
i.execute(name = name, datetime = datetime.datetime(2007, 7, 26, 23, 00, 18))


date = "2007-07-26"
test1 = sqa.select(
           [events_table.c.datetime](events_table.c.datetime),
           (sqa.func.date(events_table.c.datetime) == date) &amp;
           (events_table.c.name == name)
         ).execute().fetchone()
print "--"
print test1
print type(test1)
print type(test1[0](0))
print "-"
test2 = sqa.select(
           [sqa.func.max(events_table.c.datetime)](sqa.func.max(events_table.c.datetime)),
           (sqa.func.date(events_table.c.datetime) == date) &amp;
           (events_table.c.name == name)
         ).execute().fetchone()
print test2
print type(test2)
print type(test2[0](0))
</code></pre></div>
<hr>
<p dir="auto">---<a href="testcase.py">output</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(datetime.datetime(2007, 7, 26, 10, 23, 44),)
&lt;class 'sqlalchemy.engine.base.RowProxy'&gt;
&lt;type 'datetime.datetime'&gt;
-
(u'2007-07-26 23:00:18.0',)
&lt;class 'sqlalchemy.engine.base.RowProxy'&gt;
&lt;type 'unicode'&gt;"><pre class="notranslate"><code class="notranslate">(datetime.datetime(2007, 7, 26, 10, 23, 44),)
&lt;class 'sqlalchemy.engine.base.RowProxy'&gt;
&lt;type 'datetime.datetime'&gt;
-
(u'2007-07-26 23:00:18.0',)
&lt;class 'sqlalchemy.engine.base.RowProxy'&gt;
&lt;type 'unicode'&gt;
</code></pre></div>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/707/testcase.py">testcase.py</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">As posted here: <a href="http://groups.google.com/group/sqlalchemy/browse_thread/thread/d4c0f163f1f414e4" rel="nofollow">http://groups.google.com/group/sqlalchemy/browse_thread/thread/d4c0f163f1f414e4</a></p>
<p dir="auto">When you do a multiple-row insert, such as:</p>
<p dir="auto"><code class="notranslate">users.insert().execute(</code><br>
<code class="notranslate">{'user_id':6, 'user_name':'jack', 'password':'asdfasdf'},</code><br>
<code class="notranslate">{'user_id':7, 'user_name':'ed'},</code><br>
<code class="notranslate">{'user_id':8, 'user_name':'scott', 'password':'fadsfads'},</code><br>
<code class="notranslate">{'user_id':9, 'user_name':'bob'},</code><br>
<code class="notranslate">)</code></p>
<p dir="auto">...the 'password' field for the second and fourth rows, rather than<br>
being set to None or raising an error, take the first row's password<br>
value.<br>
While it is somewhat slack not to provide all the columns for each<br>
row, SA shouldn't really duplicate the first row's values, nei?</p>
<hr>
<p dir="auto">thats actually a huge pain in the butt to fix because there is an<br>
implicit behavior behind:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    `users.insert().execute({'a':1, 'b':2, 'c'3}, {&lt;dict2&gt;}, {&lt;dict3&gt;}, ...) `"><pre class="notranslate"><code class="notranslate">    `users.insert().execute({'a':1, 'b':2, 'c'3}, {&lt;dict2&gt;}, {&lt;dict3&gt;}, ...) `
</code></pre></div>
<p dir="auto">in that its the same as saying:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    `users.insert(values={'a':1, 'b':2, 'c'3}).execute({'a':1, 'b':2, 'c'3}, {&lt;dict2&gt;}, {&lt;dict3&gt;}, ...) `"><pre class="notranslate"><code class="notranslate">    `users.insert(values={'a':1, 'b':2, 'c'3}).execute({'a':1, 'b':2, 'c'3}, {&lt;dict2&gt;}, {&lt;dict3&gt;}, ...) `
</code></pre></div>
<p dir="auto">i.e. the statement is compiled against the parameters in the first<br>
element of execute arguments.  so they take place for subsequent<br>
execute arguments that dont override them.</p>
<p dir="auto">awareness would have to be added to ClauseElement/ANSICompiler to<br>
differentiate between compiled-in parameters and compiled-in<br>
parameters that came from execute params, and compiled.get_params()<br>
would have to check the incoming params against the original execute-<br>
params and raise an error if keys dont match.</p>
<hr>
<ul dir="auto">
<li>Mel C</li>
</ul>