[GRASS-dev] [GRASS GIS] #1517: 'DateTime' not handled by v.in.ogr

#1517: 'DateTime' not handled by v.in.ogr
-------------------------------------------+--------------------------------
Reporter: grasslandtom | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Database | Version: 6.4.2 RCs
Keywords: v.in.ogr, DateTime, TIMESTAMP | Platform: Unspecified
      Cpu: Unspecified |
-------------------------------------------+--------------------------------
steps to reproduce:

_ create a table in PostGIS-database 'test':
{{{
create table test (id INT, datetime TIMESTAMP);
SELECT addgeometrycolumn('test', 'the_geom', 4030, 'POINT', 2);
insert into test values (1, '2001-01-01 00:12:00', st_setsrid(ST_point(12,
50), 4030));
}}}

_ import in GRASS:
{{{
v.in.ogr dsn='PG:dbname=test' out=test layer='test(the_geom)'
location=new_test
}}}

This raises the error
{{{
DBMI-DBF driver error:
SQL parser error: syntax error, unexpected NAME processing 'datetime'
in statement:
create table test (cat integer, datetime datetime, id integer)
Error in db_execute_immediate()
}}}

When the location is connected to PostGIS:

_ import in GRASS
{{{
v.in.ogr -o dsn='PG:dbname=test' out=test_out layer='test(the_geom)'
}}}

raises the error
{{{
DBMI-Postgres driver error:
Cannot execute:
create table test_out (cat integer, datetime datetime, id integer)
FEHLER: Typ »datetime« existiert nicht
LINE 1: create table test_out (cat integer, datetime datetime, id in...
                                                      ^
}}}

(Sorry for the German error message. This one seems to come from the
PostgreSQL Server which was running before I set the respective
environment variables)

When the location is connected to SQLite, the import works without a
warning respective to DateTime but
{{{
db.columns test_out
}}}

raises
{{{
WARNING: SQLite driver: unable to parse decltype: datetime
WARNING: SQLite driver: unable to parse decltype: datetime
WARNING: SQLite driver: column 'datetime', SQLite type 3 is not supported
cat
id
}}}

Note that
{{{
ogrinfo 'PG:dbname=test' 'test(the_geom)'
}}}
gives in the last lines
{{{
datetime: DateTime (0.0)
id: Integer (0.0)
OGRFeature(test(the_geom)):0
   datetime (DateTime) = 2001/01/01 0:12:00
   id (Integer) = 1
   POINT (12 50)
}}}
Thus, DateTime seems to exist in OGR. Though the SQL data type is
TIMESTAMP.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1517&gt;
GRASS GIS <http://grass.osgeo.org>

#1517: 'DateTime' not handled by v.in.ogr
---------------------------+------------------------------------------------
  Reporter: grasslandtom | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.2
Component: Database | Version: 6.4.2 RCs
Resolution: invalid | Keywords: v.in.ogr, DateTime, TIMESTAMP
  Platform: Unspecified | Cpu: Unspecified
---------------------------+------------------------------------------------
Changes (by neteler):

  * status: new => closed
  * resolution: => invalid

Comment:

Replying to [ticket:1517 grasslandtom]:
...
> This raises the error
> {{{
> DBMI-DBF driver error:
> SQL parser error: syntax error, unexpected NAME processing 'datetime'
> in statement:
> create table test (cat integer, datetime datetime, id integer)
> Error in db_execute_immediate()
> }}}

You cannot use a reserved SQL word as column name. 'datetime' is
reserved...

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1517#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1517: 'DateTime' not handled by v.in.ogr
---------------------------+------------------------------------------------
  Reporter: grasslandtom | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 6.4.2
Component: Database | Version: 6.4.2 RCs
Resolution: | Keywords: v.in.ogr, DateTime, TIMESTAMP
  Platform: Unspecified | Cpu: Unspecified
---------------------------+------------------------------------------------
Changes (by grasslandtom):

  * status: closed => reopened
  * resolution: invalid =>

Comment:

Replying to [comment:1 neteler]:
> Replying to [ticket:1517 grasslandtom]:
> ...
> > This raises the error
> > {{{
> > DBMI-DBF driver error:
> > SQL parser error: syntax error, unexpected NAME processing 'datetime'
> > in statement:
> > create table test (cat integer, datetime datetime, id integer)
> > Error in db_execute_immediate()
> > }}}
>
> You cannot use a reserved SQL word as column name. 'datetime' is
reserved...

Obviously not for PostgreSQL. Otherwise the first line in the first code
block could not work. As a reference:

[http://www.postgresql.org/docs/8.3/static/sql-keywords-appendix.html\]

Further in PostgreSQL:
{{{
alter table test rename datetime to something;
}}}

then in GRASS:

{{{
v.in.ogr dsn='PG:dbname=gs_gk_workspace' out=test layer='test(the_geom)'
location=new_test
}}}

raises
{{{
DBMI-DBF driver error:
SQL parser error: syntax error, unexpected NAME processing 'datetime'
in statement:
create table test (cat integer, something datetime, id integer)
Error in db_execute_immediate()
}}}

Here it's obviously not the column name, but the data type, that causes
trouble.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1517#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>