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

    alejandrogb92

    04/14/2022, 9:28 AM
    Hello everybody! In the supabase bucket I have several csv that I would like to be able to load to a database table. Is there any way to load from a URL a csv to a table? Thank you very much! #843999948717555735
  • m

    Muezz

    04/15/2022, 1:56 PM
    Copy code
    sql
    if new."category" is "rand_category"
      then
        //Do somthing
      else
        //Do somthing else
      end if;
    Is this the correct way of checking the value of a particular column in the newly added row?
    g
    • 2
    • 2
  • g

    garyaustin

    04/15/2022, 2:15 PM
    check value in new row
  • o

    oren

    04/16/2022, 9:13 AM
    Hi, how can I get the names of the FK constraints? I tried following https://database.dev/list-all-constraint But I only get one constraint from the auth.users table.
  • g

    garyaustin

    04/16/2022, 1:49 PM
    I found this online seems to work:
    Copy code
    select * from information_schema.key_column_usage
    where constraint_catalog=current_catalog 
    and position_in_unique_constraint notnull;
  • m

    Muezz

    04/16/2022, 9:24 PM
    Can any one tell me how I can create an
    rpc
    which takes a json doc as an argument and adds not the doc itself but the data from it into a table. For instance, the
    keys
    will be the column names and the
    values
    will be the data that need to be added.
    t
    • 2
    • 26
  • m

    Muezz

    04/16/2022, 9:39 PM
    Copy code
    sql
    create or replace function insert_json(_js json)
    returns void
    language plpgsql
    as $$
    
    begin
      INSERT INTO db_transactions
      SELECT * FROM json_populate_record (NULL::db_transactions, _js);
      
    end;
    $$;
    
    insert_json({'t_date':now(),'category':'random_category','amount':120,'deb_acc':'acc_1','cred_acc':'acc_2'});
  • t

    tourdownunder

    04/16/2022, 11:59 PM
    Can any one tell me how I can create an
  • m

    Muezz

    04/17/2022, 7:38 PM
    Can somebody please help me with this issue given above? You can look at the thread to get all the context for it.
  • j

    joshcowan25

    04/18/2022, 5:00 AM
    I am currently working on a library website and we need to use DublinCore for the system. The database was design to be the most atomic possible. So we have a table books that contains main info about the books, but we also have a BY table that contains ID to books, authors, and then the Authors table it self. We have those Linking table for many relationship. Same thing goes for subjects, where we have a isAbout table and a Subjects table. When we access to a book page, we need info about the book, the authors, the subjects... So I tought about it and I think that It would be better to create a postgres function returning everything about a book then making 5 normal supabase requests. I watched some videos about functions, but it ain't more clear for me... What would I return, a JSONB object? How do I return it? ... Can anyone help we write this function or just give me tips on how to do it (or examples)?
    t
    • 2
    • 8
  • o

    oren

    04/18/2022, 12:55 PM
    Thanks!
  • j

    JonWasTaken

    04/19/2022, 3:59 AM
    (Just realized I should have posted this here after posting in #843999948717555735 - feel free to delete that one) When I run the following SQL:
    Copy code
    ALTER TABLE props ADD COLUMN textSearch tsvector GENERATED ALWAYS AS (
      setweight(to_tsvector('english', coalesce(name, '')), 'A') ||
      setweight(to_tsvector('english', coalesce(terms,'')), 'B')
    ) STORED;
    
    CREATE INDEX props_textsearch_idx ON props USING GIN (textSearch);
    I get the following error:
    Copy code
    db error: ERROR: malformed array literal: ""
    DETAIL: Array value must start with "{" or dimension information.
       0: sql_migration_connector::validate_migrations
                 at migration-engine\connectors\sql-migration-connector\src\lib.rs:271
       1: migration_core::state::DevDiagnostic
                 at migration-engine\core\src\state.rs:248
    The syntax should be correct as I've seen it in multiple sources, so I'm wondering if it's a supabase specific problem maybe?
  • j

    JonWasTaken

    04/19/2022, 4:15 AM
    I'm using prisma, fwiw, which according to garyaustin may be causing the issue, but running the same sql in supabase console resulted in the same error:
  • g

    garyaustin

    04/19/2022, 4:22 AM
    You can't use textSearch..... you have to have "textSearch" postgres is all lower case unless in double quotes... but I'm not sure how that causes the error you see.
  • j

    JonWasTaken

    04/19/2022, 4:25 AM
    Same issue with:
    Copy code
    ALTER TABLE props ADD COLUMN "textSearch" tsvector GENERATED ALWAYS AS (
      setweight(to_tsvector('english', coalesce(name, '')), 'A') ||
      setweight(to_tsvector('english', coalesce(terms,'')), 'B')
    ) STORED;
    
    
    -- CreateIndex
    CREATE INDEX props_textSearch_idx ON props USING GIN ("textSearch");
    I wonder if the issue is that the type for
    terms
    is actually
    string[]
    not just
    string
    like name is
  • g

    garyaustin

    04/19/2022, 4:27 AM
    Like I said I should bow out.... but you have props_textSearch that scares me... this is part of the prisma thing I said I'm not qualified to deal with... Postgres is not camelCase friendly. "camelCase" has to be done every where if you use it.
  • j

    JonWasTaken

    04/19/2022, 4:31 AM
    I should have caught that myself, good point. I changed all of the camelCase values to just lowercase, same issue:
    Copy code
    ALTER TABLE props ADD COLUMN search tsvector GENERATED ALWAYS AS (
      setweight(to_tsvector('english', coalesce(name, '')), 'A') ||
      setweight(to_tsvector('english', coalesce(terms,'')), 'B')
    ) STORED;
    
    
    -- CreateIndex
    CREATE INDEX searchidx ON props USING GIN (search);
  • g

    garyaustin

    04/19/2022, 4:43 AM
    I'm out for the night but I certainly agree if terms is an array that is likely a problem. https://www.postgresql.org/docs/current/functions-textsearch.html see array_to_tsvector
  • j

    JonWasTaken

    04/19/2022, 5:00 AM
    Thank you, that appears to have been the issue 🙌
  • j

    jaitaiwan

    04/19/2022, 9:25 AM
    Any recommendations for resources to learn postgresql stuff? Done a lot of sql with mysql. Postgres seems like quite the different beast
    s
    • 2
    • 1
  • s

    Scott P

    04/19/2022, 8:07 PM
    Any recommendations for resources to
  • u

    (d,f,g)=> 🥁

    04/20/2022, 8:41 PM
    how could i model something like medium's claps, where a user can make many many votes on a post/thing but with a max on their vote count having one per user is as simple as
    primary key(item_id, user_id)
    how do i write a check constraint that limits the amount of rows a user can make on an item? i dont know any way to use aggregates like max/count in indexes or check constraints...
    g
    • 2
    • 1
  • m

    Muezz

    04/20/2022, 8:53 PM
    thats pretty simple to implement I think and there are several ways to do this. You could "hard code" it into the client code where the app checks the database and if the person has already voted, you can have a notification/snack bar that says "You are not allowed to vote again". The other obvious method is to create a database function that is triggered on a new insert/update. if that user already has voted, you can stop the insert there. If it were up to me, I'd probably go with the first option because it is slightly more easy to implement but both should work.
  • g

    garyaustin

    04/21/2022, 1:29 AM
    limit votes
  • e

    ElectricDragon

    04/21/2022, 11:15 AM
    Hi, I had begun an issue on GitHub but was advised to ask for help here as well. Here is my issue link https://github.com/supabase/supabase/discussions/6456. I am having issues with inner join
    s
    s
    t
    • 4
    • 13
  • s

    Scott P

    04/21/2022, 4:52 PM
    Hi I had begun an issue on GitHub but
  • u

    (d,f,g)=> 🥁

    04/21/2022, 8:23 PM
    i'm adapting these policies from a postgraphile project, and wondering if they make sense within postgrest:
    Copy code
    sql
    create table comments (
      comment_id int primary key generated always as identity,
      user_id uuid references auth.users default auth.uid(),
      blog_slug text not null,
      parent_id int references comments,
      body text not null check(length(body) between 1 and 2000),
      created_at timestamptz not null default now()
    );
    create index on comments (blog_slug);
    create index on comments (parent_id);
    alter table comments enable row level security;
    create policy select_all on comments for select using (true);
    create policy insert_own on comments for insert with check (user_id = auth.uid());
    create policy update_own on comments for update using (user_id = auth.uid());
    create policy delete_own on comments for delete using (user_id = auth.uid());
    this this is all typical stuff, but will these work as i expect?
    Copy code
    sql
    grant select on comments to anon;
    grant
      insert (blog_slug, body, post_id, parent_id),
      update (body),
      delete
    on comments to authenticated;
    s
    • 2
    • 2
  • e

    Edgar

    04/23/2022, 10:26 PM
    Hi everyone, I am about to launch my Supabase project to production and I was wondering wether or not the CLI SQL migration tool made by Supabase is production ready or if I should go for something else (probably flyway) ? Thanks in advance for the help !
  • d

    DanMossa

    04/24/2022, 4:32 PM
    There's a thread I made in #843999948717555735 if someone could take a look. Don't wanna duplicate it
  • m

    Muezz

    04/26/2022, 8:12 PM
    Is there a built-in way/function to achieve something like this? Going from Table 1 and 2 to Table 3 (i.e. 1-2=3)
    t
    • 2
    • 28
1...394041...52Latest