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

    sumchans

    08/24/2021, 2:08 AM
    My latest try is like the below, still not working as expected const { data, error } = await supabase .from('users') .select('phone_number') .in('phone_number', LIKE ANY(ARRAY[@contacts]))
  • s

    sumchans

    08/24/2021, 2:08 AM
    The code should be converted to dart format
  • j

    jason-lynx

    08/24/2021, 2:12 AM
    how about converting contacts into an array via dart first (so that it looks like
    ['%91960000000', '%7780000000', ...]
    ), then
    Copy code
    const { data, error } = await supabase
      .from('users')
      .select('phone_number')
      .in('phone_number', @contacts)
  • j

    jason-lynx

    08/24/2021, 2:15 AM
    assuming your phone numbers stored in the db also are prefixed with '%'. else, you should remove them first
  • s

    sumchans

    08/24/2021, 5:06 PM
    Phone numbers are not stored with % sign in the database, with the percentage sign I am doing pattern matching. Contacts as an array, thats how I initially tried, that didn't work. I got a promising solution from one of the forums, but still not quite there. The solution was to create a function in Supabase and then call the function using postgrest. Example of a function -
    Copy code
    CREATE FUNCTION users_with_matching_phone_number(contacts text[]) RETURNS TABLE(phone_number text) as $$
    SELECT * FROM users WHERE phone_number LIKE ANY(contacts);
    $$ language sql;
  • s

    silentworks

    08/24/2021, 5:08 PM
    Please just link to the answer on the discussion board next time https://github.com/supabase/supabase/discussions/2938#discussioncomment-1225339
  • s

    sumchans

    08/24/2021, 5:10 PM
    Sure @User
  • s

    sumchans

    08/24/2021, 5:11 PM
    Still working on the solution, calling the function in dart with arguments is not working for me as of now.
  • s

    silentworks

    08/24/2021, 5:17 PM
    I've posted a solution on the discussion thread
  • s

    sumchans

    08/24/2021, 6:18 PM
    Thanks @User , really appreciate it.
  • p

    Peanut

    08/25/2021, 1:05 AM
    How do I get an approximate row count with the Supabase security enforcing a 1000 read limit for malicious read protection?
  • s

    soedirgo

    08/25/2021, 4:27 AM
    You can override this in Settings > API > Settings > Max Rows (and btw whole table count with
    count
    overrides that setting)
  • p

    Peanut

    08/25/2021, 4:52 AM
    > (and btw whole table count with count overrides that setting) What does this mean? I set the setting
    count
    to
    estimated
    and I get 1000 (when I know it's more - over 1600)
  • s

    soedirgo

    08/25/2021, 5:04 AM
    Does it still give 1000 when you use
    count: 'exact'
    ?
  • p

    Peanut

    08/25/2021, 8:34 AM
    It gives the correct number. I'm worried about using "exact" for performance
  • s

    soedirgo

    08/25/2021, 8:54 AM
    Yeah
    estimated
    uses the Postgres stats collector so the number tends to be off
  • p

    Peanut

    08/25/2021, 9:00 AM
    It is suspiciously the same as the security limit
  • p

    Peanut

    08/25/2021, 9:10 AM
    It is 1001 though so maybe it is just the estimate
  • w

    Waldemar

    08/25/2021, 10:44 AM
    guys, what is a safe way to drop all tables quickly? Can I just run this script as I would do in a normal Postgres DB, or will it mess up some Supabase-specific stuff?
    Copy code
    DROP SCHEMA public CASCADE;
    CREATE SCHEMA public;
    GRANT ALL ON SCHEMA public TO postgres;
    GRANT ALL ON SCHEMA public TO public;
    (Background: I'm coding a tool that migrates an Airtable base to Postgres / Supabase and need to "reset" the target Supabase tables frequently. So it is a dev/test project at the moment, but once I get the migration right, I want to continue to develop the live app on top of it, so I'm a bit paranoid it will mess up something in long run)
    s
    • 2
    • 3
  • s

    soedirgo

    08/25/2021, 11:05 AM
    Drop all tables
  • u

    user

    08/25/2021, 1:52 PM
    Hello, how can I do "select sum(column) from table group by other_column" with the API? Is it possible?
  • h

    HorseShoe

    08/25/2021, 3:12 PM
    How to refert to the object being posted in policy?
  • h

    HorseShoe

    08/25/2021, 3:13 PM
    i mean inserted
  • h

    HorseShoe

    08/25/2021, 3:13 PM
    or any operation
  • s

    silentworks

    08/25/2021, 5:01 PM
    Use a function inside the database and call it via the
    .rpc
    method
  • s

    silentworks

    08/25/2021, 5:02 PM
    It's probably to explain what you are trying to accomplish than how to refer object in policy, there might be a better way of doing this or a different approach
  • h

    HorseShoe

    08/25/2021, 5:22 PM
    Sorry i guess my question wasnt clear
  • h

    HorseShoe

    08/25/2021, 5:22 PM
    Like if am creating policy on say "messages" table
  • h

    HorseShoe

    08/25/2021, 5:23 PM
    i want to do:
    Copy code
    create policy blah blah using ( msg.user = auth.uid() AND msg.type = text )
  • h

    HorseShoe

    08/25/2021, 5:23 PM
    like that
1...789...52Latest