I'm trying this script, in ? passed GeoJson
DO $$
DECLARE
lib_table_name text;
lib_table_id text;
geom geometry;
BEGIN
SELECT
point_node_libs.lib_type,
point_node_libs.lib_type_id,
nodes.geometry
INTO lib_table_name, lib_table_id, geom
FROM point_nodes AS nodes
LEFT JOIN point_node_libs
ON point_node_libs.id = nodes.node_lib_id
WHERE ST_DWithin(geom, ST_GeomFromGeoJSON(?), 0);
EXECUTE format('
SELECT
id,
geometry,
metadata,
draft,
node_lib_id AS nodeLibId,
created_at AS createdAt,
updated_at AS updatedAt,
point_node_libs.*,
lib_table.*
FROM point_nodes AS points
LEFT JOIN point_node_libs
ON point_node_libs.id = points.node_lib_id
LEFT JOIN (
SELECT *
FROM %I
WHERE id=%s
) lib_table
WHERE $1;', lib_table_name, lib_table_id) USING (ST_DWithin(geom, ST_GeomFromGeoJSON(?), 0));
END $$;
and the error is
[22004] ERROR: null values cannot be formatted as an SQL identifier Where: PL/pgSQL function inline_code_block line 17 at EXECUTE
DB: Postgre 13.9