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

    SETY

    08/28/2021, 11:17 PM
    Copy code
    drop table if exists user_roles;
    drop type if exists custom_user_roles;
    
    CREATE TYPE custom_user_roles AS ENUM ('user','approver','admin');
    
    create table user_roles (
      id uuid references auth.users not null unique,
      role custom_user_roles not null default 'user',
    
      primary key (id)
    );
    
    alter table user_roles enable row level security;
    
    create or replace function add_default_user()
      returns trigger as
    $$
    begin
      insert into public.user_roles(id, role) VALUES (NEW.id, 'user');
      return NEW;
    end;
    $$
    language 'plpgsql' SECURITY DEFINER;
    
    drop trigger if exists default_user_role on auth.users;
    create trigger default_user_role after insert on auth.users execute procedure add_default_user();
  • s

    SETY

    08/28/2021, 11:17 PM
    When I create a user, I am getting this
  • s

    SETY

    08/28/2021, 11:18 PM
    Any idea why?
  • h

    HorseShoe

    08/29/2021, 3:50 AM
    Copy code
    sql
    WITH folders as
    select
      storage.foldername(name) as folders
    from
      storage.objects;
    folders [ 0 ] = 'avatar'
    and uid() = (
      SELECT
        rooms.owner
      FROM
        rooms
      WHERE
        rooms.id:: text = folders [ 1 ]
    )
  • h

    HorseShoe

    08/29/2021, 3:50 AM
    policies cant use with?
  • h

    HorseShoe

    08/29/2021, 3:51 AM
    am getting "syntax error near with"
  • h

    HorseShoe

    08/29/2021, 4:14 AM
    nvm i got it to work
  • p

    Peanut

    08/29/2021, 5:41 AM
    How do I replace a function used by an extension? I want to fix net.http_post (https://github.com/supabase/supabase/issues/2871 and https://github.com/supabase/pg_net/pull/38) by doing:
    Copy code
    CREATE OR REPLACE FUNCTION net."http_post"(
    But I get error:
    Copy code
    ERROR:  cannot remove parameter defaults from existing function
    HINT:  Use DROP FUNCTION net.http_post(text,jsonb,jsonb,jsonb,integer) first.
    When I try to DROP the function I get an error about it being a dependency on the
    pg_net
    extension
  • s

    SETY

    08/29/2021, 10:18 PM
    Is there anything wrong about setting up a public.users that might mess up auth.users?
  • s

    silentworks

    08/29/2021, 10:44 PM
    The question is not clear, but
    public.users
    should not affect
    auth.users
    at all unless you have setup a constraint somewhere
  • b

    burggraf

    08/29/2021, 10:45 PM
    Nothing technically wrong but I usually use a different table name like
    userprofile
    or something like that so I don’t get confused later.
  • j

    JW

    08/30/2021, 11:41 AM
    Hey I have the following problem:
    Copy code
    select
      *
    from
      calculator_screens
      inner join calculator_answers answer on answer.calculator_screen = calculator_screens.id
    That's my pure sql query, working fine. I am trying to do the same on the frontend, what would the query look like? I have a third table
    calculator_moves
    that has a foreign key to a
    calculator_answer
    and to
    calculator_screens
    . Anything I try using postgrest ends in an
    More than one relationship was found for calculator_screens and calculator_answers
    error even though
    calculator_moves
    is never touched Do i need to use stored procedure to run my query?
    s
    r
    • 3
    • 3
  • p

    Peanut

    08/30/2021, 12:01 PM
    Fixed by running it via web console (my SQL client was buggering it up)
  • s

    silentworks

    08/30/2021, 3:20 PM
    Stored procedure is the way
  • r

    Reza

    08/30/2021, 7:24 PM
    I am wondering if we could run a native (raw) SQL from js-client or flutter sdk?
  • b

    burggraf

    08/30/2021, 8:42 PM
    Generally no, you can't run raw sql because it's a big security risk. If you need raw sql create a function and call it with
    .rpc()
  • m

    Miguel2390d

    08/31/2021, 3:11 AM
    Hello
  • m

    Miguel2390d

    08/31/2021, 3:12 AM
    Does anyone know why I'm still getting a 42501 on Row Level Security
  • m

    Miguel2390d

    08/31/2021, 3:12 AM
    I made a rule with this
    Copy code
    sql
    CREATE POLICY "allow_insert"
    ON "CompanySubmissions"
    FOR INSERT WITH CHECK (
      auth.role() = 'anon'
    );
  • m

    Miguel2390d

    08/31/2021, 3:13 AM
    And I still get this:
  • m

    Miguel2390d

    08/31/2021, 3:15 AM
    Copy code
    json
    {
    "code":"42501",
    "message":"new row violates row-level security policy for table \"CompanySubmissions\""
    }
  • j

    jason-lynx

    08/31/2021, 4:16 AM
    do you also have a policy that allows selects?
  • j

    jason-lynx

    08/31/2021, 4:16 AM
    it's also needed if i recall right, because by default the newly inserted row will be selected and returned
  • b

    burggraf

    08/31/2021, 1:07 PM
    That is true, unless you pass an extra parameter to the
    .insert
    of
    { returning: 'minimal' }
  • y

    yurix

    08/31/2021, 2:55 PM
    I am having trouble with the supabase api to filter queries that include foreign relations. I've tried with the 'match', 'filter' and 'eq' modifiers, but none seem to work. This would be an example of what I am doing, could someone tell me the correct way to achieve this?
    Copy code
    -- # EXAMPLE TABLES
    TABLE public.projects (
      id: TEXT
      name: TEXT,
    )
    
    TABLE public.sheets (
      id uuid primary key default uuid_generate_v4(),
      project_id not null references public.projects(id)
    
      name: TEXT,
    )
    
    -- # EXAMPLE QUERY
    const { data, error } = await supabase
      .from('sheets')
      .select(
    *, project:project_id ( name, )
    Copy code
    )
      .match({ "sheets.name": 'sheet_name' })
    Currently this returns all the records from the table sheets to me, without filtering anything. Why?
  • y

    yurix

    08/31/2021, 3:08 PM
    I have found this issue on github, does that mean I can't do it? What other options do I have? https://github.com/supabase/postgrest-js/issues/197
    s
    • 2
    • 2
  • s

    soedirgo

    08/31/2021, 4:32 PM
    Embedded table
  • c

    Crane

    08/31/2021, 6:20 PM
    hello folks, what are some recommended sources to learn about database (postgre) & query language like sql?
    s
    s
    +2
    • 5
    • 5
  • c

    Crane

    08/31/2021, 6:21 PM
    I used to take one class in community college but I feel like I need to learn more about how to design the schema and master sql to be able to make use of supabase
  • s

    Scott P

    08/31/2021, 6:35 PM
    Learning resources
1...121314...52Latest