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

    jon.m

    09/02/2021, 2:00 AM
    @User use this website, it's great
  • j

    jon.m

    09/02/2021, 2:01 AM
    https://pgexercises.com/
  • j

    jon.m

    09/02/2021, 2:03 AM
    How would I set up a function in plpgsql that checks to see if a row already exists and then executes procedures conditionally based on that query?
    j
    • 2
    • 2
  • s

    stibbs

    09/02/2021, 5:13 AM
    In one of my tables I want a column that contains an array. I've defined it as
    categories text[] not null,
    . Table creates successfully, but if I try to enter values directly in the supabase dashboard everything I try is an invalid array? Ultimately I want to input something like this from my JS:
    ["this + that", "and", "another"]
    . What does this translate to in the dashboard? The psql docs (https://www.postgresql.org/docs/9.1/arrays.html) say to use
    {}
    and quotation marks but these all give
    Invalid Array
  • s

    stibbs

    09/02/2021, 6:45 AM
    I have no idea what changed, but it now works with exactly what I started with...
    ["this + that", "and", "another"]
  • j

    jason-lynx

    09/02/2021, 10:18 AM
    plpgsql
  • n

    Nico Maybach

    09/03/2021, 9:29 AM
    How can I assign the auth.uid() to a row for example to created_by?
    Copy code
    BEGIN
      NEW.created_by = auth.uid();
      RETURN NEW;
    END;
    -> Error: more than one row returned by a subquery used as an expression
    j
    • 2
    • 6
  • j

    jason-lynx

    09/03/2021, 9:29 AM
    try
    :=
    ?
  • j

    jason-lynx

    09/03/2021, 9:31 AM
    although it shouldnt make a difference...
  • n

    Nico Maybach

    09/03/2021, 9:31 AM
    same error :/
  • m

    mornir

    09/03/2021, 11:22 AM
    Hey! I'm new to Supabase and I'm using for a side project. That project let users review their day (like a journal). So I have a reviews table and RLS policies were easy to implement (users can only read/write their own reviews). But now I'd like users to be able to become a member of a group. Once in a group, everybody can view each other's reviews. The problem I have is to write the RLS policy so that group members can only view each other's reviews. I followed this example https://supabase.io/docs/guides/auth#policies-with-joins, but when I tried my policy, a user could access all reviews (even from other group). Could somebody share a minimal demo of that RLS policy, in the same fashion as in that doc example?
    s
    w
    s
    • 4
    • 43
  • s

    SETY

    09/03/2021, 12:37 PM

    https://www.youtube.com/watch?v=JXeDNpecfD0â–¾

  • s

    SETY

    09/03/2021, 12:43 PM
    The issue we have is we have to implement our own roles, and not use the postgres ones, because the users are auth.user
  • s

    SETY

    09/03/2021, 12:44 PM
    so I mirrored the auth.user table with a trigger, and am now in the process of working through how I am going to make my own custom roles
  • s

    silentworks

    09/03/2021, 1:10 PM
    RLS with select query
  • s

    SETY

    09/03/2021, 5:52 PM

    https://www.youtube.com/watch?v=Ow_Uzedfohkâ–¾

    EVEN BETTER
  • e

    Evаn

    09/04/2021, 4:28 AM
    for people figuring out how to do auth and roles etc, I'm finding https://github.com/supabase/supabase/blob/master/examples/nextjs-slack-clone/full-schema.sql a really useful reference
  • s

    SETY

    09/04/2021, 9:36 AM
    just curious anyway to see the code for auth.uid()?
  • s

    silentworks

    09/04/2021, 2:16 PM
    You can see it here https://github.com/supabase/supabase/discussions/2986#discussioncomment-1251406
  • s

    SETY

    09/04/2021, 3:02 PM
    Thank you
  • r

    RichCorbs

    09/04/2021, 10:40 PM
    Anyone had issues with foreign key relationships after renaming a table?
  • m

    mendesrenan5

    09/05/2021, 5:44 PM
    I needed to remove the foreign key reference from the table, delete the respective column, create a new column and make it a foreign key again. The problem was solved after that. Hope it this works for you
  • u

    user

    09/05/2021, 7:50 PM
    i'm having trouble setting up a one to many relation, my lack of sql experience isn't helping here 😅 here are my tables (the relevant properties): buckets: id: uuid, columnIds: uuid[] columns: id: uuid i want to set up a relation on columnIds pointing to columns.id here's what I try, and I get the error "Error updating foreign key: foreign key constraint "buckets_columnIds_fkey" cannot be implemented"
  • u

    user

    09/05/2021, 7:50 PM
    (hopefully it's not confusing calling my table "columns" but I can't think of a better name lol)
  • s

    stibbs

    09/06/2021, 1:06 AM
    That is definitely a confusing name for a table lol
  • s

    stibbs

    09/06/2021, 1:07 AM
    What are you trying to achieve? I'm struggling to follow
  • s

    stibbs

    09/06/2021, 1:13 AM
    Making something 1:many in psql should just be adding something like below into the "child" table.
    bucket_id uuid references buckets not null,
  • s

    stibbs

    09/06/2021, 1:14 AM
    E.g.
    Copy code
    sql
    CREATE TABLE buckets (
      id uuid generated by default as identity primary key,
      name text,
    );
    
    CREATE TABLE columns (
      id uuid generated by default as identity primary key,
      bucket_id uuid references buckets not null,
      name text,
    );
  • s

    stibbs

    09/06/2021, 1:16 AM
    You don't need to use uuid for every id, only use it when you really need it
  • s

    stibbs

    09/06/2021, 1:16 AM
    Often a
    bigint
    is enough - but happy for someone to teach me otherwise 🙂
1...131415...52Latest