Skip to content

Conversation

@TimMoser92
Copy link
Contributor

I removed some schemas from the data dump. I only kept the schemas ga and ga_efa. The old dump also contained postgis and postgis_raster relations and the extenions themselves. That was introduced by #85 but was not caught, because in the local developer docker compose environment the data dump is imported as the database superuser postgres. But in a cloud (testing) environment where this dump could be used, this is typically not the case. I took the existing dump, imported it, and exported only those schemas with all relations.

@sebeweiss is there any specific/necessary data in these relations that the backend (or the demo application) requires? Or can we remove those parts of the dump safely?

I found a bug when asking for Nearest Neighbour with an address given, but could not safely track if that arose from these changes or had been broken before:

query: SELECT * FROM ((SELECT $1 AS "topic", $2 AS "id", json_build_object(
      'type', 'FeatureCollection',
      'features', jsonb_agg(
        jsonb_set(
          ST_AsGeoJSON(custom_from_select.*)::jsonb,
          '{geometry}',
          ST_AsGeoJSON(
          CASE
            WHEN ST_IsEmpty(custom_from_select.geom)
            THEN custom_from_select.geom
            ELSE ST_Transform(custom_from_select.geom, 4326)
          END
        )::jsonb
        )
      ))
     AS "response" FROM (SELECT name, nationalcode, geometrieflaeche, geometrieflaeche_eh, geom, ST_distance(ST_TRANSFORM($3::text, 25832), geom) AS "__dist" FROM "ga_efa"."th_verwaltungseinheit_f" "th_verwaltungseinheit_f" ORDER BY __dist ASC LIMIT 5) "custom_from_select" WHERE custom_from_select.__dist <= $4)) "union_query" -- PARAMETERS: ["th_verwaltungseinheit_f","__ID_0","SRID=4326;POLYGON ((13.818211 51.0101, 13.827823 51.012908, 13.830226 51.008157, 13.820957 51.006969, 13.818211 51.0101))",2000]
query: SELECT * FROM ((SELECT $1 AS "topic", $2 AS "id", json_build_object(
      'type', 'FeatureCollection',
      'features', jsonb_agg(
        jsonb_set(
          ST_AsGeoJSON(custom_from_select.*)::jsonb,
          '{geometry}',
          ST_AsGeoJSON(
          CASE
            WHEN ST_IsEmpty(custom_from_select.geom)
            THEN custom_from_select.geom
            ELSE ST_Transform(custom_from_select.geom, 4326)
          END
        )::jsonb
        )
      ))
     AS "response" FROM (SELECT strasse, str_nummer, plz, ort, geom, ST_distance(ST_TRANSFORM($3::text, 25833), geom) AS "__dist" FROM "ga"."adresse_p" "adresse_p" ORDER BY __dist ASC LIMIT 5) "custom_from_select" WHERE custom_from_select.__dist <= $4)) "union_query" -- PARAMETERS: ["adresse_p","__ID_0","SRID=4326;POLYGON ((13.818211 51.0101, 13.827823 51.012908, 13.830226 51.008157, 13.820957 51.006969, 13.818211 51.0101))",2000]
query failed: SELECT * FROM ((SELECT $1 AS "topic", $2 AS "id", json_build_object(
      'type', 'FeatureCollection',
      'features', jsonb_agg(
        jsonb_set(
          ST_AsGeoJSON(custom_from_select.*)::jsonb,
          '{geometry}',
          ST_AsGeoJSON(
          CASE
            WHEN ST_IsEmpty(custom_from_select.geom)
            THEN custom_from_select.geom
            ELSE ST_Transform(custom_from_select.geom, 4326)
          END
        )::jsonb
        )
      ))
     AS "response" FROM (SELECT strasse, str_nummer, plz, ort, geom, ST_distance(ST_TRANSFORM($3::text, 25833), geom) AS "__dist" FROM "ga"."adresse_p" "adresse_p" ORDER BY __dist ASC LIMIT 5) "custom_from_select" WHERE custom_from_select.__dist <= $4)) "union_query" -- PARAMETERS: ["adresse_p","__ID_0","SRID=4326;POLYGON ((13.818211 51.0101, 13.827823 51.012908, 13.830226 51.008157, 13.820957 51.006969, 13.818211 51.0101))",2000]
error: error: ST_Distance: Operation on mixed SRID geometries (Polygon, 25833) != (Point, 0)
[Nest] 1  - 01/12/2026, 9:15:08 AM   ERROR [ExceptionsHandler] QueryFailedError: ST_Distance: Operation on mixed SRID geometries (Polygon, 25833) != (Point, 0)
    at PostgresQueryRunner.query (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:216:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async SelectQueryBuilder.loadRawResults (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2231:25)
    at async SelectQueryBuilder.getRawMany (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/query-builder/SelectQueryBuilder.js:646:29)
    at async _typeorm.SelectQueryBuilder.<computed> (/app/dist/metrics/database-metrics.subscriber.js:51:32)
    at async GeneralService.generelRoutine (/app/dist/general/general.service.js:280:26)
    at async GeneralService.calculateMethode (/app/dist/general/general.service.js:260:20)
    at async NearestNeighbourController.nearestNeighbour (/app/dist/nearest-neighbour/nearest-neighbour.controller.js:38:16) {
  query: `SELECT * FROM ((SELECT $1 AS "topic", $2 AS "id", json_build_object(\n      'type', 'FeatureCollection',\n      'features', jsonb_agg(\n        jsonb_set(\n          ST_AsGeoJSON(custom_from_select.*)::jsonb,\n          '{geometry}',\n          ST_AsGeoJSON(\n          CASE \n            WHEN ST_IsEmpty(custom_from_select.geom) \n            THEN custom_from_select.geom\n            ELSE ST_Transform(custom_from_select.geom, 4326)\n          END\n        )::jsonb\n        )\n      ))\n     AS "response" FROM (SELECT strasse, str_nummer, plz, ort, geom, ST_distance(ST_TRANSFORM($3::text, 25833), geom) AS "__dist" FROM "ga"."adresse_p" "adresse_p" ORDER BY __dist ASC LIMIT 5) "custom_from_select" WHERE custom_from_select.__dist <= $4)) "union_query"`,
  parameters: [
    'adresse_p',
    '__ID_0',
    'SRID=4326;POLYGON ((13.818211 51.0101, 13.827823 51.012908, 13.830226 51.008157, 13.820957 51.006969, 13.818211 51.0101))',
    2000
  ],
  driverError: error: ST_Distance: Operation on mixed SRID geometries (Polygon, 25833) != (Point, 0)
      at /app/node_modules/.pnpm/pg@8.16.3/node_modules/pg/lib/client.js:545:17
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async PostgresQueryRunner.query (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:181:25)
      at async SelectQueryBuilder.loadRawResults (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2231:25)
      at async SelectQueryBuilder.getRawMany (/app/node_modules/.pnpm/typeorm@0.3.27_pg@8.16.3_reflect-metadata@0.2.2_ts-node@10.9.2_@swc+core@1.15.2_@types+node@24.10.1_typescript@5.9.3_/node_modules/typeorm/query-builder/SelectQueryBuilder.js:646:29)
      at async _typeorm.SelectQueryBuilder.<computed> (/app/dist/metrics/database-metrics.subscriber.js:51:32)
      at async GeneralService.generelRoutine (/app/dist/general/general.service.js:280:26)
      at async GeneralService.calculateMethode (/app/dist/general/general.service.js:260:20)
      at async NearestNeighbourController.nearestNeighbour (/app/dist/nearest-neighbour/nearest-neighbour.controller.js:38:16) {
    length: 134,
    severity: 'ERROR',
    code: 'XX000',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'lwgeom_pg.c',
    line: '363',
    routine: 'pg_error'
  },

@TimMoser92 TimMoser92 requested a review from sebeweiss January 15, 2026 10:22
@sebeweiss
Copy link
Collaborator

Thanks for the reduction. I don't see any need for the relations and have also successfully tested with your dump.

BUT you're right, there is a problem with the addresses. In the k8s environment, they are retrieved via a view. When creating the dump (#85), the SRID was incorrectly not set.

You can check it with SELECT ST_SRID(geom) FROM ga.adresse_p LIMIT 1;. This should not return 0, but it does.
This is why we get the error: driverError: error: ST_Distance: Operation on mixed SRID geometries (Polygon, 25833) != (Point, 0)

Here's how to fix it:

UPDATE ga.address_p
SET geom = ST_SetSRID(geom, 25833)
WHERE ST_SRID(geom) = 0;

I'll fix it later. If you have everything open right now, you can also do it if you want.

SRID of address data was 0 instead of 25833 due to an error during export
@TimMoser92
Copy link
Contributor Author

Great, that was the missing piece. Since I actually did have everything open from the last export, I ran your query and exported again. Will test shortly if it fixed the problem.

Copy link
Collaborator

@sebeweiss sebeweiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much. It works :)

@TimMoser92 TimMoser92 merged commit 26b7af7 into main Jan 15, 2026
1 check passed
@TimMoser92 TimMoser92 deleted the fix/reduce-data-dump branch January 15, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants