[development] no date / time types in schema API

Barry Jaspan barry at jaspan.org
Thu Jul 17 15:58:03 UTC 2008


"augustin (beginner)" <drupal.beginner at wechange.org> writes:
> All (but one) SQL dialects have a date type.  However, Drupal's
> Schema API does not seem to have a type for date only:
> http://drupal.org/node/159605
> 
> Is this a purposeful omission?  What workarounds do you use?

It is not so much a purposeful omission as a problem I did not put
effort into solving because, when I asked, no one told me it mattered.

To have a Schema API type for dates and times require that it be able
to map meaningfully to a native db type on all dbs we want to support.
I thought that date and time types would be inconsistent between
various dbs.  I did put in one type, datetime, that works on mysql and
pgsql, but did not try to find portable types for time and date
separately.

That said, there is a workaround: You can declare db-specific column
types in the Schema API field structure, using mysql_type and
pgsql_type, like this:

  $schema['mytable'] = array(
    'fields' => array( 'mycolumn' => array('mysql_type' => 'date',
      'pgsql_type' => 'whatever', ....)));


> There is probably a better way to truncate the time part (please
> say), but it feels a shame to have to deal with the extraneous time
> part when Schema API could easily handle date types.


If you have a specific suggestion for what the Schema API date and
time related types should be and how they should map to mysql and
pgsql native types, by all means submit an issue at d.o.

Thanks,

Barry



More information about the development mailing list