[SOLVED] Passing parameter to lua file


I’m just switching my data flow to osm2pgsql using flex output and LUA. It’s already working really well (excellent performance !!).

My osm2pgsql-script somewhere calls

osm2pgsql … -O flex -S lua/my_lua_file.lua …

and the LUA-file says

local poi = osm2pgsql.define_table({
name = ‘osm_dach_poi’,
ids = { type = ‘any’, type_column = ‘osm_type’, id_column = ‘osm_id’ },

i.e. the name of the POI table is fixed here. This is quite error-prone, as it has to be adjusted for each test. Sometimes I have forgotten this, which has ruined hours of work.


Is there any way to pass this table name (osm_dach_poi) from the osm2pgsql script to lua? Or set a global variable?

I’m working with Ubuntu 22.04-1 LTS and osm2pgsql 1.7.0


You have access to environment variables in Lua with os.getenv("VAR"). So something along the lines of:

local poi = osm2pgsql.define_table({
name = os.getenv("CUSTOM_TABLE_NAME"),
ids = { type = ‘any’, type_column = ‘osm_type’, id_column = ‘osm_id’ },

together with

CUSTOM_TABLE_NAME=osm_dach_poi osm2pgsql ... -O flex ...

should work.

1 Like

yes, that works fine :slight_smile: