ANTON KADACH

Generation

text to sql syntaxTue, 17 Jan 2023

Geo_objects(id, level) geo_objects_attributes(id, name) geo_polygons(geo_id, simple_geometry) product_region(longitude, latitude, fias_id) запрос, который находит гео-объекты максимального level по координатам долготе и широте через функции ST_Intersects(gp.simple_geometry , ST_Transform(ST_SetSRID(ST_Point(p.longitude::numeric, p.latitude::numeric), 4326), 3857)) в таблице geo_polygons и обновляет поле "fias_id" значением из поля external_id таблицы geo_objects_attributes в таблице product_region. Язык postgresql

WITH max_level AS ( SELECT MAX(level) AS level FROM geo_objects ), max_geo_id AS ( SELECT go.id AS geo_id FROM geo_objects go JOIN max_level ml ON ml.level = go.level ), max_geo_attr_id AS ( SELECT goa.id AS geo_attr_id FROM geo_objects_attributes goa JOIN max_geo_id mgi ON mgi.geo_id = goa.geo_id ), intersects_points AS ( SELECT DISTINCT p.fias_id AS fias_id, gpa.external_id AS external_id, p.id AS id FROM max_geo_id mgi JOIN geo_polygons gp ON gp.geo_id = mgi.geo_id JOIN product_region p ON ST_Intersects(gp.simple_geometry , ST_Transform(ST_SetSRID(ST_Point

Questions about programming?Chat with your personal AI assistant