-
Notifications
You must be signed in to change notification settings - Fork 28
Watch not working with IN and ANY Query. #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So I think this boils down to the query not being valid (it might be valid for Postgres which supports some additional syntax that SQLite does not, which is why you can run it when managing the instance).
var stream = db.watch(
'SELECT * FROM events WHERE creator_user = ?1 OR ?1 IN (SELECT value FROM json_each(manager_ids)) ORDER BY start_date ASC', parameters: [FFAppState().user.userId]);
eventsSubscription = stream.listen((data) {
callback(data.map((json) => EventsRow(Map<String, dynamic>.from(json))).toList());
});
That's something we should take a look at (I would the query to report an error), thanks! I think the stream you're listening to should emit an error event, and since you don't have an |
Hi @simolus3, Apologies, but none of the suggested solutions have worked for me. After applying the json_each query, it works successfully in the PowerSync Diagnostics tool but does not trigger updates in the Flutter app.
I have attached screenshots for better clarity. Please take a look and let me know if there's a possible fix. |
So at least we know that there is an error getting logged after all :)
Given that |
Yes, the declaration resolved the crash issue, but the data is still not loading. Please check the attachment—I declared it as follows, but I can't find the integer array in the schema:
I can retrieve only exact matches, but queries using IN are not working. |
The There might be an issue on our side here, I'm just wondering if it works when you manually change the type to |
I'm syncing data from Supabase Postgres. The same query executes correctly in the console and even appears correctly in diagnostics, but in the app, it only returns results for exact matches (=) and does not work with IN. |
Is that still true after changing To help us understand what's causing us to miss the type here, could you please run the following query in the PowerSync dashboard and share the results (I know it's quite long, that's the query we use internally to figure out types, I've changed it so that it only reports the single row for the SELECT
tbl.schemaname,
tbl.tablename,
tbl.quoted_name,
json_agg(a ORDER BY attnum) as columns
FROM
(
SELECT
n.nspname as schemaname,
c.relname as tablename,
(quote_ident(n.nspname) || '.' || quote_ident(c.relname)) as quoted_name
FROM
pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE
c.relkind = 'r'
AND c.relname = 'events' -- only include the one table we care about here
AND n.nspname not in ('information_schema', 'pg_catalog', 'pg_toast')
AND n.nspname not like 'pg_temp_%'
AND n.nspname not like 'pg_toast_temp_%'
AND c.relnatts > 0
AND has_schema_privilege(n.oid, 'USAGE') = true
AND has_table_privilege(quote_ident(n.nspname) || '.' || quote_ident(c.relname), 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER') = true
) as tbl
LEFT JOIN (
SELECT
attrelid,
attname,
format_type(atttypid, atttypmod) as data_type,
(SELECT typname FROM pg_catalog.pg_type WHERE oid = atttypid) as pg_type,
attnum,
attisdropped
FROM
pg_attribute
) as a ON (
a.attrelid = tbl.quoted_name::regclass
AND a.attnum > 0
AND NOT a.attisdropped
AND has_column_privilege(tbl.quoted_name, a.attname, 'SELECT, INSERT, UPDATE, REFERENCES')
)
GROUP BY schemaname, tablename, quoted_name |
@simolus3 Thanks for your kind support! Please find the following requested details by executed your query in powersync dashboard.
And the following way, I have added in flutter code
Let me know if needed to refactor any. |
Thanks for posting the results, we're looking into this!
I think that should be everything. Does the query work now that you've changed the type here? |
I am using PowerSync in my Flutter app, and I need to listen for real-time updates in my local database. However,
db.watch
is not triggering updates when changes occur in the synced tables.Code Implementation
This is how I'm using db.watch in my app:
The query works as expected in the PowerSync console but does not work inside the Flutter app.
Even when testing via the PowerSync diagnostics platform, the query does not return results.
There issue in IN and ANY Query.
Screenshots
The following screenshots illustrate the issue:
I have verified that the table is updating correctly by running sync rules.
No errors or exceptions appear in the logs related to db.watch.
Manually querying the database reflects expected changes, but the listener does not trigger.
Would appreciate any guidance on resolving this issue. Thanks in advance! 🚀
The text was updated successfully, but these errors were encountered: