not sure if this is an issue in Servoy or with the driver or whatever;
If you have a query where you have an unnamed column, caused by simply using a constant as a placeholder, databaseManager.getDataSetByQuery may not return the result.
SELECT person_id, 0 FROM people WHERE person_name ILIKE ?
fails even if there are people records that satisfy the criteria. Changing it to
SELECT person_id, 0 as zero FROM people WHERE person_name ILIKE ?
works. Both version work when executed outside of Servoy, directly in PostgreSQL 12.
I construct a query in Servoy as a string. Pass it together with an array of parameters to getDataSetByQuery();
When it does not work, I output the query string using application.output() and paste it into DataGrip where it works.
Maybe the problem is that
SELECT some_field, 0 FROM some_table WHERE some_thing
causes Servoy assume the column is called 0 which may not be allowed because it starts with a number.
Why do I do this kind of thing? Set operations (UNION, UNION ALL, INTERSECT etc) in PostgreSQL combining or slicing data from tables that have little in common.
The data can be used as in-memory data sources… very powerful…
Anyway, the workaround (0 as something) is very simple. I just thought I’d mention it in case someone else hits the same problem.
var ds = databaseManager.getDataSetByQuery("example_data","select node_id, 0 from book_nodes where node_id = ?",[1],100);
application.output(ds);
ds = databaseManager.getDataSetByQuery("example_data","select node_id, 0 as zero from book_nodes where node_id = ?",[1],100);
application.output(ds);