2

I have a table like this:

CREATE TABLE IF NOT EXISTS features
(
    features_id integer NOT NULL,
    bbox character varying 200,
    geom geometry NOT NULL,
    CONSTRAINT features_pkey PRIMARY KEY (features_id)
);

I neet to insert a geom and its correspondent extent in this table so I tried this:

insert into features (features_id, bbox, geom) VALUES 
(default, 
ST_AsGeoJSON( ST_Extent(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-43.3568056,-22.9115278],[-43.3568056,-22.9118056],[-43.3565278,-22.9118056],[-43.3565278,-22.9115278],[-43.3568056,-22.9115278]]]}'))), 
ST_GeomFromGeoJSON(' {"type":"Polygon","coordinates":[[[-43.3568056,-22.9115278],[-43.3568056,-22.9118056],[-43.3565278,-22.9118056],[-43.3565278,-22.9115278],[-43.3568056,-22.9115278]]]} ') )

but seems I can't have ST_AsGeoJSON and ST_Extent inside an INSERT:

ERROR: aggregate functions are not allowed in VALUES

How can I achieve this?

1 Answer 1

5

You can use ST_Envelope instead of ST_Extent, as the latter is an aggregate function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.