Using QGIS 3.22.11.

I have a project with a layer tree_pt. tree_pt contains 17 point features. I wish to obtain the geometry for each feature in WKT format using SQL. (I have similar layers containing line and polygon features, which I will treat similarly once I have got this working).

Using DB Manager, the following SQL results in what appears to be zero-length strings for each of the 17 features.

FROM tree_pt

Screenshot of SQL and query output

I would expect the output to contain 17 rows, each containing the geometry in WKT format, e.g. Point (564.13737133 214.32729203), or similar.

Is there something wrong in my SQL or approach, or is this a bug?

  • 1
    what sort of database is it? I'd usually use st_aswkt but I'm a postgis user
    – Ian Turton
    Jan 9, 2023 at 16:35
  • They're SHP files accessed via a QGIS project, so no inbuilt SQL engine. SQL will be provided via QGIS
    – Oisin
    Jan 9, 2023 at 16:37
  • 2
    try out st_astext(geometry) instead geom_to_wkt Jan 9, 2023 at 16:43
  • 1
    @ Marco - this works. Add it as an answer and I'll mark it as acceprted solution. Thanks
    – Oisin
    Jan 9, 2023 at 16:59
  • 2
    It seems that not all QGIS functions from the expression engine work in the SQL engine. The DB Manager doesn't complain, it just doesn't generate a column for them. select geom_from_wkt('POINT(0 1)') from tree_pt returns empty, select nonsuch('POINT(0 1)') from tree_pt returns "no such function".
    – Spacedman
    Jan 9, 2023 at 17:07

1 Answer 1


Try out st_astext(geometry) instead geom_to_wkt.

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.