I'm now trying to use the eval() function in a Virtual Layer in QGIS. The version of QGIS is 3.28.4-Firenze, and it contains the SpatiaLite (version 5.0.1) which includes the eval() function as below.

SpatiaLite 5.0.1 SQL functions reference list: https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.0.1.html

However, my Virtual Layer cannot execute the query because:

"Query preparation error on PRAGMA table_info(_tview): no such function: eval".

Before the execution of SQL, I set the path using set SPATIALITE_SECURITY=relaxed in OSGeo4W Shell.

Is there any solution?

  • 2
    Perhaps you are not setting the environment variable correctly. I would think that the environment that is created when opening the OSGeo4W Shell console is not the same environment that QGIS is running in. Perhaps it is better to define it in the QGIS Options, System tab. Mar 18, 2023 at 19:35

1 Answer 1


This is an interesting question that has piqued my interest. As I'm working in QGIS Windows, I set SPATIALITE_SECURITY=relaxed in the global Windows environment.

After many trials and errors, I found a syntax that worked in a virtual layer query:

select eval('select mycol from mytable',',')
from mytable
limit 1
  • Thank you for your reply. I can use the eval() function by setting SPATIALITE_SECURITY=relaxed in the global Windows environment. However, I can get the table containing the SQL query statement. Can I get the virtual layer/table? Or are there any points I missed?
    – Lc_decg
    Mar 21, 2023 at 9:59
  • 1
    @Lc_decg maybe I don't understand your question completely, but I guess you want to know if you can retrieve all table records. Unfortunately, eval() returns only a string.
    – christoph
    Mar 21, 2023 at 13:04

Your Answer

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

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