Direct Database Query - tableName as variable

Answered

Hi,

new to Xano but not to building apps. We're porting an existing app to xano so i started with datamigration. Every table (about 70 of them) has a updatedAt field. We use this field to determine what the last point was that the table content was synchronised.

Initially i've build a function that has an enum named table as input. That function returns the max(updatedAt) from a table. The first 5 build by hand using a conditional then, when matched with the input, ran a query all records that returned the value.

Expanding this to 70+ tables sounds like A LOT of work. So in comes the DIRECT DATABASE QUERY. I've buidl a LAMBDA FUNCTION that translates the input (table_name:ENUM) to it's corresponding technical table name (like X3_31).

I want to use the DIRECT DATABASE QUERY 'SELECT MAX('updatedAt') FROM ?' and pass the technical table name as variable to the ?.

This however returns:

'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near '$1' LINE 1: SELECT MAX('updatedAt') FROM $1 ^ (SQL: SELECT MAX('updatedAt') FROM x3_31)'

Who knows a way around this issues?

4 replies