Skip to content

Commit

Permalink
postgres table name bug when - is present in table name
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Oct 12, 2024
1 parent 9a50b2c commit 2bb6890
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duckdb-postgis"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
authors = ["chris@enmeshed.dev", "serj@enmeshed.dev"]
description = "A library for transforming geospatial data using DuckDB and ingesting it into a PostGIS database."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

This Rust library uses DuckDB and serves as a data transformation layer in the Gridwalk architecture.

## Current v0.1.3 release notes
## Current v0.1.4 release notes

### This Rust library does the following things:

Expand All @@ -14,7 +14,7 @@ This Rust library uses DuckDB and serves as a data transformation layer in the G
- Performs CRS transformation on the data if required - ensuring the CRS is ESPG:4326
- Loads the data into a PostGIS table with a correctly defined geometry column

### Improvements for release 0.1.4:
### Improvements for release 0.1.5:

- Handle raster data file formats
- Discard rows where there may be errors in the geometry column / ensure the programme doesn't crash when a geometry error is encountered - skip over it and log it instead
10 changes: 5 additions & 5 deletions src/duckdb_load/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ impl DuckDBFileProcessor {

// Execute CRUD logic
let delete_if_table_exists_query =
&format!("DROP TABLE IF EXISTS gridwalk_db.{};", self.table_name);
&format!("DROP TABLE IF EXISTS gridwalk_db.\"{}\";", self.table_name);
self.conn.execute(delete_if_table_exists_query, [])?;

let create_table_query = &format!(
"CREATE TABLE gridwalk_db.{} AS SELECT * FROM transformed_data;",
"CREATE TABLE gridwalk_db.\"{}\" AS SELECT * FROM transformed_data;",
self.table_name
);
self.conn.execute(create_table_query, [])?;
Expand All @@ -264,9 +264,9 @@ impl DuckDBFileProcessor {
let mut postgis_queries = Vec::new();
for geom_column in geom_columns {
postgis_queries.push(format!(
"ALTER TABLE {} ADD COLUMN {} geometry;
UPDATE {} SET {} = ST_GeomFromText({}_wkt, 4326);
ALTER TABLE {} DROP COLUMN {}_wkt;",
"ALTER TABLE \"{}\" ADD COLUMN {} geometry;
UPDATE \"{}\" SET {} = ST_GeomFromText({}_wkt, 4326);
ALTER TABLE \"{}\" DROP COLUMN {}_wkt;",
self.table_name,
geom_column,
self.table_name,
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ mod duckdb_load;
use duckdb_load::launch_process_file;

fn main() -> Result<(), Box<dyn std::error::Error>> {
launch_process_file("FILE NAME HERE", "TABLE NAME HERE", "POSTGIS URI HERE")?;
launch_process_file(
"test_files/hotosm_twn_populated_places_points_geojson.geojson",
"my-table",
"postgresql://admin:password@localhost:5432/gridwalk",
)?;
Ok(())
}

0 comments on commit 2bb6890

Please sign in to comment.