Search code examples
sqlitecastingcreate-table

Cast text to numeric in sqlite table definition


is there a cast in sqlite, I need this to work in a create table definition ...

....
mydatetime numeric not null DEFAULT (strftime('%Y%m%d%H%M','now', 'localtime')) );

thanks


Solution

  • sqlite> .headers on
    sqlite> CREATE TABLE t1 (mydatetime int not null DEFAULT (strftime('%Y%m%d%H%M',
    'now', 'localtime')), otherval TEXT);
    sqlite>
    sqlite> INSERT INTO t1 (otherval) VALUES ('qwe');
    sqlite> SELECT * FROM t1;
    mydatetime|otherval
    201201231947|qwe