You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何监听Supabase中parent字段为NULL的实时数据变更?

监听Supabase中parent字段为NULL的数据实时变更解决方案

你当前的过滤器写法parent IS NULL不符合Supabase Realtime的语法规则,Realtime的过滤器遵循PostgREST查询规范,判断NULL值需要使用parent=is.null的格式。

修改后的可用代码如下:

const { createClient } = require('@supabase/supabase-js')

const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY, {})

// 设置自定义JWT
supabase.realtime.setAuth('your-custom-jwt')

const channel = supabase
  .channel('db-changes')
  .on(
    'postgres_changes',
    {
      event: '*',
      schema: 'public',
      table: 'todos',
      filter: 'parent=is.null',
    },
    (payload) => console.log(payload)
  )
  .subscribe()

核心注意点

  • Supabase Realtime不支持SQL原生的IS NULL判断,必须用PostgREST规定的字段名=is.null格式来匹配NULL值。
  • 确认public.todos表的parent字段存在,且已为该表开启Realtime监听权限。

内容的提问来源于stack exchange,提问作者Sathish Kannan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 23:25:05