From 4d83e61cd52218be36af8101d796ceb25bd121b1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 24 Sep 2026 14:47:08 -0700 Subject: [PATCH] use timestamp column type in example configs --- flex-config/attributes.lua | 22 ++++++++-------------- flex-config/track-changes.lua | 10 +++------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/flex-config/attributes.lua b/flex-config/attributes.lua index 3e61ad626..b17cf11b5 100644 --- a/flex-config/attributes.lua +++ b/flex-config/attributes.lua @@ -15,14 +15,12 @@ tables.nodes = osm2pgsql.define_node_table('nodes', { { column = 'geom', type = 'point', projection = srid }, { column = 'version', type = 'int' }, { column = 'changeset', type = 'int' }, - -- There is no built-in type for timestamps in osm2pgsql. So we use the - -- PostgreSQL type "timestamp" and then have to convert our timestamps - -- to a valid text representation for that type. + -- The timestamp of the object is available as a number (seconds since + -- the epoch), osm2pgsql converts it for the "timestamp" column type. -- -- Timestamps in OSM are always in UTC, depending on your use case you -- might want to store them using "timestamptz" instead. - -- See https://github.com/openstreetmap/osm2pgsql/issues/1785 - { column = 'created', sql_type = 'timestamp' }, + { column = 'created', type = 'timestamp' }, { column = 'uid', type = 'int' }, { column = 'user', type = 'text' }, }) @@ -32,7 +30,7 @@ tables.ways = osm2pgsql.define_way_table('ways', { { column = 'geom', type = 'linestring', projection = srid }, { column = 'version', type = 'int' }, { column = 'changeset', type = 'int' }, - { column = 'created', sql_type = 'timestamp' }, + { column = 'created', type = 'timestamp' }, { column = 'uid', type = 'int' }, { column = 'user', type = 'text' }, { column = 'nodes', type = 'text', sql_type = 'bigint[]' }, @@ -42,16 +40,12 @@ tables.relations = osm2pgsql.define_relation_table('relations', { { column = 'tags', type = 'jsonb' }, { column = 'version', type = 'int' }, { column = 'changeset', type = 'int' }, - { column = 'created', sql_type = 'timestamp' }, + { column = 'created', type = 'timestamp' }, { column = 'uid', type = 'int' }, { column = 'user', type = 'text' }, { column = 'members', type = 'jsonb' }, }) -local function format_date(ts) - return os.date('!%Y-%m-%dT%H:%M:%SZ', ts) -end - function osm2pgsql.process_node(object) if next(object.tags) == nil then return @@ -62,7 +56,7 @@ function osm2pgsql.process_node(object) geom = object:as_point(), version = object.version, changeset = object.changeset, - created = format_date(object.timestamp), + created = object.timestamp, uid = object.uid, user = object.user }) @@ -74,7 +68,7 @@ function osm2pgsql.process_way(object) geom = object:as_linestring(), version = object.version, changeset = object.changeset, - created = format_date(object.timestamp), + created = object.timestamp, uid = object.uid, user = object.user, nodes = '{' .. table.concat(object.nodes, ',') .. '}' @@ -86,7 +80,7 @@ function osm2pgsql.process_relation(object) tags = object.tags, version = object.version, changeset = object.changeset, - created = format_date(object.timestamp), + created = object.timestamp, uid = object.uid, user = object.user, members = object.members diff --git a/flex-config/track-changes.lua b/flex-config/track-changes.lua index cf9e3a094..0e0c489e5 100644 --- a/flex-config/track-changes.lua +++ b/flex-config/track-changes.lua @@ -19,7 +19,7 @@ local change_table = osm2pgsql.define_table{ -- 'M' for modified, -- 'D' for deleted { column = 'action', type = 'text' }, - { column = 'date', sql_type = 'timestamp' } + { column = 'date', type = 'timestamp' } }, indexes = { { column = { 'osm_type', 'osm_id' }, method = 'btree' } @@ -31,10 +31,6 @@ local change_table = osm2pgsql.define_table{ -- being processed. local file_reading_in_progress = true -local function format_date(ts) - return os.date('!%Y-%m-%dT%H:%M:%SZ', ts) -end - local function add_object_change(object) -- In this example only changes while updating the database are recorded. -- This happens in 'append' mode. @@ -44,7 +40,7 @@ local function add_object_change(object) osm_id = object.id, version = object.version, action = (object.version == 1) and 'A' or 'M', - date = format_date(object.timestamp) + date = object.timestamp } end end @@ -64,7 +60,7 @@ local function add_deleted_object(object) osm_id = object.id, version = object.version, action = 'D', - date = format_date(object.timestamp) + date = object.timestamp } end