4

I am trying to use the SQL Execute in the graph modeler, receiving as input the output of another algorithm. The problem is that I couldn't specify that the "input" in the FROM of the SQL Execute should be the "output" of the process prior to it. This makes batch execution impossible, as I can only execute by specifying in FROM, the name of a table that is already in canvas. It's curious because, although I'm working inside the modeler, with the execute SQL properly linked in the previous process, it insists on fetching the table in the canvas. Is there any way to specify in SQL to fetch from the previous table? Below, I share the query I am trying to execute and the image of the modeler:

SELECT *, MAX ("area_segm") as 'area_segm_'
FROM "27a_SUBOBJETOS_UTEIS"
GROUP BY "id_objeto"

Graphic Modeler

Important! When I run it for the first time, it results in the following message: Referenced table 27a_SUBOBJECTS_UTEIS in query not found!

When I run it again, it works because the 27a_SUBOBJETS_UTEIS layer has already been added to the canvas, and the Execute SQL algorithm looks there.

I already tried it the way below, but it didn't work either.

SELECT *, MAX ("area_segm") as 'area_segm_'
FROM "output"
GROUP BY "object_id"

I just have to figure out what I should write after FROM, to get the result of the algorithm 27a from my model as input.

Lilium
1,0651 gold badge8 silver badges17 bronze badges
asked Mar 16, 2022 at 4:39
2
  • 2
    have you tried writing in FROM input1? FROM input1 docs.qgis.org/testing/en/docs/user_manual/processing_algs/qgis/… Commented Mar 16, 2022 at 15:19
  • 1
    By including FROM "input1" as indicated, the expression worked perfectly. This is a full solution. Thanks a lot for your tip. Commented Mar 17, 2022 at 1:50

2 Answers 2

3

The solution is described in the QGIS guide at this link, in short you have to use

FROM input1

answered Mar 17, 2022 at 7:48
0

If the query you included in the question is the only thing to calculate, you could take a look at the Statistics by categories tool, which can also calculate a max value with a group field.

Still the solution for using a model output in a sql query would be interesting for other purposes.

answered Mar 16, 2022 at 14:56
1
  • 1
    Thanks for the help, I didn't know this algorithm yet. I think it will be very useful, but it only generates the table, it doesn't generate a new vector bringing only the ones with the largest areas within each object. By including FROM "input1" as indicated by MrXsquared, the expression worked perfectly. But thanks again for your tip. Commented Mar 17, 2022 at 1:47

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.