Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

how-to for INSERTing a PostGIS geometry without a TRIGGER #273

Closed
steve-chavez opened this issue Nov 7, 2019 · 3 comments · Fixed by #516
Closed

how-to for INSERTing a PostGIS geometry without a TRIGGER #273

steve-chavez opened this issue Nov 7, 2019 · 3 comments · Fixed by #516
Labels
references Technical reference.

Comments

@steve-chavez
Copy link
Member

The idea is to use the geometry literal representation:

select 'SRID=4326;POINT(54.729142 25.268204)'::geometry
-- result: 0101000020E6100000ED116A86545D4B4009A87004A9443940 

So, simply:

create table bla(a geometry);

http POST localhost:3000/bla << JSON
{"a": "SRID=4326;POINT(54.729142 25.268204)"}
JSON

No need for a TRIGGER!

(This comes from https://gitter.im/begriffs/postgrest?at=5dc46507a03ae1584f85d77b)

@steve-chavez steve-chavez added the how-tos Goal oriented guides. Not in depth. label Nov 7, 2019
@steve-chavez
Copy link
Member Author

Found the idea on https://gis.stackexchange.com/a/68756/153225.

@steve-chavez
Copy link
Member Author

Same question on stackoverflow: https://stackoverflow.com/questions/62221504/insert-update-postgis-geometry-column-with-postgrest/62246461#62246461.

Also, wonder if we should have a SO link somewhere, similarly to: https://dhall-lang.org/

@steve-chavez
Copy link
Member Author

Turns out that hstore also needs something similar:

create table test.hstore_test(id int, settings hstore);

http POST localhost:3000/hstore_test <<JSON
{"id": 1, "settings": "ORGCTE => DE, ORGNAME => Bundesamt"}
JSON

http GET localhost:3000/hstore_test
[
    {
        "id": 1,
        "settings": {
            "ORGCTE": "DE",
            "ORGNAME": "Bundesamt"
        }
    }
]

(Got this thanks to Oleg from https://gnuhost.eu/)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
references Technical reference.
Development

Successfully merging a pull request may close this issue.

1 participant