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

    claud9

    08/19/2021, 8:17 PM
    Has anyone used
    PGP_SYM_ENCRYPT
    or have any examples?
    • 1
    • 1
  • d

    dailylurker

    08/20/2021, 12:16 AM
    Hmm but the problem with this is there's no row yet right? Since it's before insert.
  • s

    Scott P

    08/20/2021, 12:42 AM
    You might be right about that, but it could be worth a try. It's been a long day and my brain isn't working properly right now, but it's possible that it creates the row with
    admin_id
    set to
    auth.uid()
    and then inserts the other values in the same row - sort of like modifying it in-place before committing the transaction to the DB. Another option is to put the other values from
    new
    into the query: e.g.
    INSERT INTO public.my_table(admin_id, some_string, some_number) VALUES (auth.uid(), new.some_string, new.some_number)
    . Another option which might work would be to set the column default to
    auth.uid()
    . That way, whenever a new row is inserted, it'll automatically set the value of the
    admin_id
    column to
    auth.uid()
    .
    d
    • 2
    • 1
  • d

    dailylurker

    08/20/2021, 2:17 AM
    Insert trigger to change value for new before insert
  • q

    quicksnap

    08/20/2021, 4:41 AM
    Sometimes a RLS Policy subquery can have a name conflict and silently use the wrong context! FUN. Like, I have a table that has column
    t1.blah_blah
    and I wanted to use that column in a subquery who also had a column of the same name (
    ... where foo.blah_blah = blah_blah
    ). Instead of warning me, it just used the unqualified name from
    foo
    .. which is always true, and really tripped me up.
    b
    • 2
    • 7
  • q

    quicksnap

    08/20/2021, 4:43 AM
    Had to fix it by using a
    with
    clause. Here's my redacted SQL:
    Copy code
    USING (
      -- .. snip ..
      and
      user_id in (
        with foo as (select blah_blah) 
        select 
          owner_id 
        from 
          wave_blips wb, 
          foo 
        where 
          wb.blah_blah = foo.blah_blah 
        and 
          wb.owner_id = user_id
    )
  • q

    quicksnap

    08/20/2021, 4:43 AM
    I'm just annoyed. that is all.
  • q

    quicksnap

    08/20/2021, 4:43 AM
    took me like 45 minutes staring at it going "WHY?!"
  • q

    quicksnap

    08/20/2021, 4:44 AM
    because I'm too lazy to set up a local env, I had no way of debugging via
    raise notice
    or whatever, and there's no way to "run" a policy other than using it
  • b

    burggraf

    08/20/2021, 3:20 PM
    Debugging SQL
  • q

    quicksnap

    08/20/2021, 6:03 PM
    Update: turns out I was wrong and @User pointed out I could have just qualified it using the table name to which the policy applies.
  • m

    MrWolf

    08/21/2021, 2:22 AM
    Maybe I should have put this question here: https://canary.discord.com/channels/839993398554656828/843999948717555735/878463314840158280
  • p

    Peanut

    08/21/2021, 11:21 AM
    How do I SELECT a record by using a property inside some JSONB as the id? Structure:
    Copy code
    table "mysuperspecialtable"
      id: TEXT = 'activeUsers',
      value: JSONB =
        {
          "activeUserId": "abcdef"
        }
    Something like:
    Copy code
    SELECT
              username,
              avatarurl
        FROM mysuperspecialtable
        LEFT JOIN users ON users.id = (mysuperspecialtable.value ->> 'activeUserId')::TEXT
        WHERE
            mysuperspecialtable.id = 'activeUsers'
    How do I grab the user's record using that property? I have tried everything I can think of (Some context is I am converting Firestore to PostgreSQL and I stored some references to docs in an array)
    s
    • 2
    • 5
  • p

    Peanut

    08/21/2021, 3:16 PM
    Why does PostgREST give me a 404 error when I try to update a record that has a RLS policy that prevents updating? When I satisfy the RLS policy it returns 200
    b
    • 2
    • 5
  • t

    ThePhilip

    08/21/2021, 6:29 PM
    I have another database in my postgres instance and I can't delete it because supabase_admin is always accessing it
  • s

    sumchans

    08/22/2021, 7:58 PM
    Hello all, anybody here who is a dart and postgres experts please help out. I am trying to make this query work. Here the contacts is a dart string variable with a lot of phone numbers in it with this format
    '%91960000000’,’%7780000000',’%6720000000',’%4160000000','%7780000000'
    . With this query I am not getting any errors, but I am supposed to get two records returned, but I get a blank array returned.
    Copy code
    final results = await postgresConnection.query(
              "SELECT display_name,phone_number FROM public.users WHERE phone_number LIKE (@contacts)",
              substitutionValues: {"contacts": contacts});
  • o

    Olyno

    08/22/2021, 10:22 PM
    @User Please do not ask in every channel. Plus, can you put your code in a code tag please? Using \`\`\` around your code
  • s

    sumchans

    08/22/2021, 10:23 PM
    I was told to put it over here
  • s

    sumchans

    08/22/2021, 10:23 PM
    I can remove from the other chat
  • s

    sumchans

    08/22/2021, 10:23 PM
    Sure will do
  • d

    dailylurker

    08/23/2021, 2:21 PM
    Hi all, how can we get more details about the sql execution? I have 2 triggers that calls their own function on my insert one before the insert to update the column value and one to update another table, my problem is only the second one is happening and I can't seem to find any details why the other is not happening
    b
    • 2
    • 5
  • s

    sumchans

    08/23/2021, 10:55 PM
    I am out of forums to post the above question. It's been a week already. Anybody who has expertise in postgrest, supabase, dart please help out.
  • b

    burggraf

    08/24/2021, 12:52 AM
    Debugging Triggers
  • j

    jason-lynx

    08/24/2021, 1:39 AM
    does it work if you replace
    LIKE
    with
    IN
    ?
  • j

    jason-lynx

    08/24/2021, 1:40 AM
    i dont use dart but am assuming the '@' has a special meaning for substitution
  • j

    jason-lynx

    08/24/2021, 1:43 AM
    oh sorry just saw you mentioned it's a string variable. what about
    WHERE phone_number LIKE '%(@contacts)%'
    ?
  • s

    sumchans

    08/24/2021, 1:47 AM
    The values inside the array has the percentage sign on it.
  • s

    sumchans

    08/24/2021, 1:49 AM
    Like you see in the example above that's how the values of the contacts variable is rendered.
  • j

    jason-lynx

    08/24/2021, 1:51 AM
    so it's an array? or is it just a long string?
  • s

    sumchans

    08/24/2021, 2:04 AM
    It's a long string
1...678...52Latest