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

    jason-lynx

    09/21/2021, 2:52 AM
    https://www.postgresql.org/docs/current/sql-grant.html
    GRANT ALL ON <view name> TO service_role
  • j

    jason-lynx

    09/21/2021, 2:52 AM
    btw, for RLS to work, you dont have to set
    authenticated
    as the owner of the view
  • j

    jason-lynx

    09/21/2021, 2:53 AM
    RLS should work for non-table owners as well
  • p

    Peanut

    09/21/2021, 2:59 AM
    It doesn't seem to. Any user could look at RLS-restricted records by using the view. When I changed the owner to
    authenticated
    then it started being restricted
  • p

    Peanut

    09/21/2021, 2:59 AM
    IIRC it is because views are executed from the perspective of the user who created them
  • j

    jason-lynx

    09/21/2021, 3:07 AM
    ah ok then i probably recalled wrongly
  • s

    SETY

    09/21/2021, 10:44 AM
    @User RLS is executed at the level of the user who implments it. Can you show an exmaple?
  • s

    SETY

    09/21/2021, 10:44 AM
    Also once you turn on RLS for a table, every action is now restricted until you specifically clarify the policy
  • s

    SETY

    09/21/2021, 1:30 PM
    I have a view that mashes together my public.users and the auth.users. RLS works from the public.users table on it. I may be crazy
  • l

    LuddensEkko

    09/21/2021, 6:17 PM
    hi, say i have a *Post and Comment tables, and l need each Post record to contain a list of its comments, how can i do that?
  • s

    SETY

    09/21/2021, 11:59 PM
    in the comment table put a foreign key to the post
  • s

    stibbs

    09/22/2021, 8:18 AM
    I asked this in the javascript channel but it's more appropriate here. I want to auto calculate a datetime 30 days in the future and put it in
    valid_until
    . Below does not work.
    Copy code
    ts
    await supabase
      .from('posts')
      .update({ valid_until: `now() + interval '30 day'` })
      .eq('id', postId);
    However using just
    .update({ valid_until: 'now()'})
    works (but doesn't achieve my goal)
  • b

    bnjmnt4n

    09/22/2021, 8:50 AM
    I don't think you can pass in arbitrary text which will be treated as SQL expressions. I think the easiest workaround is to do this client side, or you can create a function which you invoke via
    supabase.rpc
    in which you can then use whatever SQL expressions you need
  • s

    stibbs

    09/22/2021, 8:51 AM
    Cheers, a function is probably the go then 👍
  • s

    stibbs

    09/22/2021, 9:15 AM
    Fwiw it’s not arbitrary text, that’s psql datetime operators but maybe they aren’t considered valid in an update statement?
  • b

    bnjmnt4n

    09/22/2021, 1:11 PM
    Haven't dug deeply into it, but I suspect postgrest treats most inputs as text to avoid possible sql injection operations
  • m

    Mattias

    09/22/2021, 2:45 PM
    Stored procedure
    • 1
    • 2
  • r

    ra9

    09/25/2021, 11:48 AM
    Hey! guys is there a way to convert an sql table to the supabase ways of doing it?
    s
    • 2
    • 13
  • r

    ra9

    09/25/2021, 11:49 AM
    Copy code
    sql
    -- CreateTable
    CREATE TABLE "User" (
        "uid" TEXT NOT NULL,
        "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
        "updatedAt" TIMESTAMP(3),
        "username" TEXT NOT NULL,
        "email" TEXT NOT NULL,
        "password" TEXT NOT NULL,
        "role" "Role" NOT NULL DEFAULT E'USER',
    
        CONSTRAINT "User_pkey" PRIMARY KEY ("uid")
    );
  • r

    ra9

    09/25/2021, 11:49 AM
    How can I turn the above code into supabase schema and then use policy and what a view
  • s

    silentworks

    09/25/2021, 12:04 PM
    SQL in supabase
  • s

    stibbs

    10/01/2021, 2:16 AM
    If I run the following via the SQL editor it always results in a new version of
    my_func
    (which means I have duplicates). How do I force the
    replace
    part to work?
    create or replace function my_func(...
  • j

    jason-lynx

    10/01/2021, 2:21 AM
    it probably means your input/output arguments across the old and new versions are different, resulting in 2 separate functions with the same name from the docs: https://www.postgresql.org/docs/current/sql-createfunction.html > However, functions and procedures of different argument types can share a name (this is called overloading). > > To replace the current definition of an existing function, use CREATE OR REPLACE FUNCTION. It is not possible to change the name or argument types of a function this way (if you tried, you would actually be creating a new, distinct function). Also, CREATE OR REPLACE FUNCTION will not let you change the return type of an existing function. To do that, you must drop and recreate the function.
  • s

    stibbs

    10/01/2021, 2:22 AM
    Yes the input arguments are changing
  • s

    stibbs

    10/01/2021, 2:22 AM
    So I should delete the old one before running my query?
  • j

    jason-lynx

    10/01/2021, 2:23 AM
    yes, if you dont want to have multiple functions with the same name
  • s

    stibbs

    10/01/2021, 2:23 AM
    Fair enough
  • s

    stibbs

    10/01/2021, 2:25 AM
    Thanks!
  • s

    SETY

    10/01/2021, 1:47 PM
    Any chance supabase is going to update to 14?
    s
    • 2
    • 1
  • s

    silentworks

    10/01/2021, 2:21 PM
    Postgres 14 upgrade
1...171819...52Latest