https://supabase.com/ logo
Join Discord
Powered by
# sql
  • s

    stibbs

    10/20/2021, 9:03 PM
    Hoping for a little advice to set up infinite scroll 🙏
    s
    • 2
    • 16
  • m

    mikebarkmin

    10/20/2021, 9:18 PM
    I am getting an infinite recursion
    infinite recursion detected in policy for relation "conversation_users"
    on inserting to conversation_users. I thought creating a security definer function would solve this, but it did not. Does anybody has an idea?
    Copy code
    sql
    CREATE OR REPLACE FUNCTION get_conversation_users_for_authenticated_user()
    returns setof uuid
    language sql
    security definer
    set search_path = public
    stable
    as $$
        SELECT DISTINCT user_id FROM conversation_users WHERE conversation_id IN (
            SELECT DISTINCT conversation_id FROM conversation_users WHERE user_id = auth.uid()
        )
    $$;
    
    CREATE POLICY "Can select conversation_users" ON public.conversation_users AS PERMISSIVE FOR
    SELECT TO public USING (
        user_id IN (
            SELECT get_conversation_users_for_authenticated_user()
        )
    );
    
    CREATE POLICY "Can update to conversation_users" ON public.conversation_users AS PERMISSIVE FOR
    UPDATE To public USING (
        conversation_id IN (SELECT id FROM conversations WHERE admin_id = auth.uid())
    ) WITH CHECK (
        conversation_id IN (SELECT id FROM conversations WHERE admin_id = auth.uid())
    );
    
    CREATE POLICY "Can insert to conversation_users" ON public.conversation_users AS PERMISSIVE FOR
    INSERT To public WITH CHECK (
        conversation_id IN (SELECT id FROM conversations WHERE admin_id = auth.uid())
    );
    
    CREATE POLICY "Can delete from conversation_users" ON public.conversation_users AS PERMISSIVE FOR
    DELETE TO public USING (
        (conversation_id IN (SELECT id FROM conversations WHERE admin_id = auth.uid()))
        OR (user_id = auth.uid())
    );
    j
    • 2
    • 5
  • j

    jason-lynx

    10/21/2021, 2:53 AM
    infinite recursion
  • e

    easystreet

    10/21/2021, 8:32 PM
    sql jwt testing
  • s

    stibbs

    10/24/2021, 9:00 AM
    Does psql's
    to_tsvector()
    cache the document (table?) for some period? I have the below query. I ran it and correctly got 3 results. I then updated one of the rows to set
    closed = true
    and correctly got 2 results. I then updated that row back to
    closed = false
    and still only get 2 results??
    Copy code
    sql
    select *
      from public.jobs j
      where j.closed = false
        and j.valid_until > now()
        and to_tsvector(j.business_name) || ' ' ||
        array_to_tsvector(j.categories)
        @@ plainto_tsquery('demand');
  • s

    stibbs

    10/24/2021, 9:05 AM
    If I drop the
    j.closed
    and
    j.valid_until
    checks it still only gives 2 results... hmmm
  • s

    stibbs

    10/24/2021, 9:09 AM
    That specific row just won't turn up anymore
  • s

    stibbs

    10/24/2021, 11:28 AM
    Super wierd, it's like that record doesn't exist if I use
    to_tsvector
  • s

    stibbs

    10/24/2021, 11:34 AM
    fml needed to
    coalesce
    a field
  • m

    Mattias

    10/25/2021, 8:54 AM
    Query foreign table
    • 1
    • 3
  • f

    ferminrp

    10/25/2021, 12:59 PM
    Hey everyone, I'm fairly new to supabase and databases in general. I'm trying to build a simple news site where each article has multiple entities mentioned. For example "Google and snapchat sign an agreement" would have two entities Google and Snapchat.
    s
    • 2
    • 2
  • f

    ferminrp

    10/25/2021, 12:59 PM
    I was wondering how to build and structure the tables so that I can see all articles for an entity
  • f

    ferminrp

    10/25/2021, 1:00 PM
    but also see all entities on an article
  • f

    ferminrp

    10/25/2021, 1:00 PM
    I started with something like this where the articles entities array had every detail on entities ... but this definitely doesnt sound like the right aproach
  • f

    ferminrp

    10/25/2021, 1:03 PM
    Here's an example of what I mean
  • s

    silentworks

    10/25/2021, 1:35 PM
    Database structure for multiple relationship table
  • m

    M1K3

    10/25/2021, 4:22 PM
    Hey guys. How do I push into an array using supabase's JS client? Would this be with the "update" method?
  • t

    Thomas B

    10/25/2021, 4:24 PM
    https://supabase.io/docs/guides/database/arrays
  • m

    M1K3

    10/25/2021, 4:24 PM
    thanks
  • m

    M1K3

    10/25/2021, 4:24 PM
    I guess to give more insight. This is what the column is set up as
  • m

    M1K3

    10/25/2021, 4:25 PM
    did I do this correctly lol?
  • m

    M1K3

    10/25/2021, 4:25 PM
    I want it to be an array that holds IDs (text)
  • m

    M1K3

    10/25/2021, 4:26 PM
    meant to say strings mb
  • t

    Thomas B

    10/25/2021, 4:26 PM
    Looks correct then, yes.
  • m

    M1K3

    10/25/2021, 4:26 PM
    ok
  • m

    M1K3

    10/25/2021, 4:27 PM
    so right now those are empty when the user creates their account. Say they like something and I insert into the column, how would I update the column so it just pushes a new value to the array once it happens again?
  • m

    M1K3

    10/25/2021, 4:31 PM
    oh wait im stupid i figured it out
  • t

    Thomas B

    10/25/2021, 4:42 PM
    👌 🤣
  • s

    stibbs

    10/26/2021, 9:02 AM
    Is there a good way to test psql functions directly from the supabase ui?
    h
    • 2
    • 8
  • h

    HarryET

    10/26/2021, 10:42 AM
    Testing psql Functions
1...202122...52Latest