How to insert timestamp with timezone record into a postgresql database

724 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted

Chintan Pathak

unread,
Sep 18, 2019, 4:58:28 AM9/18/19
to GAMA
Dear all,

I am trying to insert timestamp with timezone field (current simulation time) into a PostgreSQL column (exists with similar datatype). I can make the connection to the database, and run the models "Create  BuildingTablePostGIS" and "Agents to Database in PostGIS" successfully. I am also able to insert into a PostgreSQL table records of several datatypes, but timestamp.

I tried to use date("now"), starting_date, current_date - in several formats using the string formatters- 'yyyy-MM-dd hh:mm:ss' etc. however I get an error during the insertion attempt.  The error is as under:

2 occurrences in 2 agents at cycle 0: SQLSkill.insert: SQLConnection.insertBD SQLConnection.insertBD org.postgresql.util.PSQLException: ERROR: syntax error at or near "01"
  Position: 111
in
in
in do insert (params:POSTGRES, columns:['origin','destination','cd_combo','cd_chademo','update_ts'], values:[98001,98002,45.67,78.85,date('now')], into:'od_cd');
in init  {
    write 'This model will work only if the corresponding database is installed and the database management server launched.' color: #red ;
    date starting_date <- date('2019-07-01 00:00:00+07:00');
    write 'Current Time ' + (self.timeStamp()) ;
    write 'Connection to POSTGRESQL is ' + (self.testConnection(params:POSTGRES)) ;
    write date('now') ;
    do insert (params:POSTGRES, columns:['origin','destination','cd_combo','cd_chademo','update_ts'], values:[98001,98002,45.67,78.85,date('now')], into:'od_cd');
}

in agents Simulation 0, default_expr0

I tried several datatypes in my PostgreSQL column like timestamp without a timezone, time without timezone - still, the insertion does not succeed. How should the timestamp data be specified in GAMA to insert it into a timestamp (with timezone) field?

Chintan Pathak

unread,
Sep 20, 2019, 3:13:06 AM9/20/19
to GAMA
Dear all,

How can I turn the flag "DEBUG" to on? I want to look the output of this line (https://github.com/gama-platform/gama/blob/42083434cce1ce8d4680c6881554b3a208bac7de/irit.gaml.extensions.database/src/msi/gama/database/sql/PostgresConnection.java#L164) which prints the insert string to the database. Looking at it will help determine the problem.

Thanks

Kevin Chapuis

unread,
Sep 20, 2019, 6:12:08 AM9/20/19
to gama-p...@googlegroups.com
Dear,

The DEBUG variable is only accessible using the git version of Gama. You can then turn it on in Eclipse (here is the java class on github).

Best,
Kevin

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/15402f3f-ad55-4ab7-88f6-a17130d28387%40googlegroups.com.


--
Chapuis kevin
Post-Doc / Research Fellow
IRD, UMI 209 UMMISCO
Reply all
Reply to author
Forward
0 new messages