1

I've set up the following DB Fiddle: https://dbfiddle.uk/mzsp-4tg

How should I make a correct SQL query to use like on geo_json field of json type to get table records with string matching coordinates combination %30.504106925781265,50.43731985018662% ?

asked Apr 3, 2023 at 18:16
1
  • Have you considered not storing coordinates as JSON? Commented Apr 3, 2023 at 18:33

1 Answer 1

0

If you store or convert the column to jsonb then you can use JSONpath

SELECT *
FROM polygon_versions
WHERE jsonb_path_exists(
 geo_json,
 '$.geoJSON.geometry.coordinates[*] ? (@[0] == 30.504106925781265 && @[1] == 50.43731985018662)');

db<>fiddle

answered Apr 3, 2023 at 18:38
3
  • How can I fix the following ERROR: function jsonb_path_exists(json, unknown) does not exist LINE 3: WHERE jsonb_path_exists( ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 38 Commented Apr 11, 2023 at 14:11
  • I have the following PostgreSQL version: PostgreSQL 14.7 (Debian 14.7-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit Commented Apr 11, 2023 at 14:22
  • Is the column json or jsonb? This only works with jsonb so either change the column's data type, or convert it like this WHERE jsonb_path_exists(geo_json::jsonb, ... Commented Apr 14, 2023 at 0:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.