sqlite3 and dates

Frank Millman frank at chagford.com
Wed Feb 18 02:49:10 EST 2015


"Chris Angelico" <rosuav at gmail.com> wrote in message 
news:CAPTjJmrB+55CVgN6zTUawRf=rzn9LTaVi5TzhJSYvHHywK1vOw at mail.gmail.com...
> On Wed, Feb 18, 2015 at 5:19 PM, Frank Millman <frank at chagford.com> wrote:
>> However, the following does not return a date object -
>>
>>>>> cur.execute('SELECT CAST(? AS DATE)', ('2015-03-31',))
>> <sqlite3.Cursor object at 0x00FE9BE0>
>>>>> cur.fetchone()
>> (2015,)
>>>>>
>>
>> I don't know how easy this would be to implement, but it would be nice if 
>> it
>> could be made to work.
>
> Heh! Looks like the date is implemented as a slightly magical integer,
> so "cast to date" becomes "cast to integer" and you just get back
> 2015. Could be really easy to fix, could be nigh impossible... but
> sure, that seems a reasonable thing to ask for. Worst case, you get
> told it's not practical.
>
> But if you need more facilities than SQLite3 can offer, maybe it's
> time to move up to a full database server, instead of local files.
> Switching to PostgreSQL will give you all those kinds of features,
> plus a lot of other things that I would have thought pretty basic -
> like ALTER TABLE. It was quite a surprise to learn that SQLite3 didn't
> support that.
>

My accounting software supports three databases - MS Sql Server, PostgreSQL, 
and sqlite3.

sqlite3 is not suitable for 'heavy-duty' applications, but it is ideal for 
demos and one-man businesses. Anyone can try out my software so long as they 
have python installed. They do not have to set up a database.

sqlite3 does support ALTER TABLE, but with limited functionality. I think 
all you can do is add a column.

Frank






More information about the Python-list mailing list