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

    Melon Husk

    12/10/2021, 12:25 PM
    Hi, I need some help in updating an jsonb[], this is how my schema looks like, { "id":"8a015caf-aa3b-4044-9f88-9f64fbcdbf8e", "question":"Test question 2", "options":[ { "id":"cf38e648-fbd8-4b20-9fb7-bdd0476d71e5", "text":"option1", "votes":0}, { "id":"c23ef382-3a27-4a15-bca0-ab156bdaad24", "text":"option2", "votes":0 } ], "total_votes":0 }
    t
    • 2
    • 2
  • m

    Melon Husk

    12/10/2021, 12:27 PM
    How would like to find an option by id and increment the votes of that option by 1 ?
  • m

    Melon Husk

    12/10/2021, 12:28 PM
    This is how I did it using mongoose/mongodb
    Copy code
    ts
    const poll = await Poll.updateOne(
              { "options.id": req.query.id },
              {
                $inc: { "options.$.votes": 1 },
              }
            );
  • i

    imousart

    12/11/2021, 11:45 PM
    hi guys .. im new in supabase also in development ^^ but i was wondering how can i pull data through an api from e.g airtable and cashing it in supabase and then used these data from supabase api
    t
    • 2
    • 3
  • i

    imousart

    12/11/2021, 11:45 PM
    is that could happen ?
  • t

    tourdownunder

    12/12/2021, 4:03 AM
    pull data through an api
  • t

    tourdownunder

    12/12/2021, 5:54 AM
    update jsonb
  • m

    Mihai

    12/13/2021, 5:01 PM
    Hello, can you cancel before an update event with a trigger function ?
    s
    • 2
    • 2
  • s

    silentworks

    12/13/2021, 8:55 PM
    Cancel before an update with trigger function
  • a

    ashbressler

    12/13/2021, 11:59 PM
    Hi All, I'm trying to modify the database in my project using DBeaver, I can connect no problem and see everything, but when I try to make any changes to the DB I get 'ERROR: must be owner of table xxxxxx', I used the credentials in the UI but it seems like that might using a different user to create tables? Any help is appreciated
    j
    • 2
    • 4
  • j

    jason-lynx

    12/14/2021, 6:16 AM
    table owner
  • e

    erik_flywheel

    12/14/2021, 10:27 AM
    Hey everyone, question on returning messages in a specific order. I have a messaging component in my application and I'm trying to return the latest 5 messages to the user in a reverse order (newest message last / at the bottom, like a messaging app). Any advice how to do this? I have the limit set, so I'm getting the 5 latest, but when I try to sort, if I do it desc, then I get the 5 oldest messages. Any ideas?
  • m

    mueslirieger

    12/14/2021, 11:52 AM
    @User Did you find a solution to your problem? Otherwise, sorting by desc should get you the the five newest messages but reversed for your purpose, so the newest message would be the first row that is returned. You could use this as a subquery and reverse the returned rows again, like so:
    select * from (select * from messages order by sent_at desc limit 5) m order by sent_at asc
    .
  • e

    erik_flywheel

    12/14/2021, 12:32 PM
    that sounds about right, will give it a try. I was thinking there should be some order of operations sort desc (to get the latest first), limit 5, then sort asc or something similar
  • g

    gleki

    12/16/2021, 7:29 AM
    Is there an example of authentication/access to auth table using direct connection to the database?
  • j

    jason-lynx

    12/16/2021, 8:01 AM
    you can see the auth table by running
    SELECT * FROM auth.users
    if you have the necessary permissions, for example via the Supabase UI SQL editor
  • g

    gleki

    12/16/2021, 8:24 AM
    I mean how do I do authenticated requests not via supabase js orm but via direct connection to postgres
  • c

    chipilov

    12/16/2021, 12:57 PM
    Authenticated requests in Supabase are handled by an intermediate server called PostgREST - supabase.js's requests are actually sent to PostgREST, PostgREST then inspects the token send by the request and then sends a request to the db by setting the necessary configuration options on the connection/session so that auth.uid(), auth.email() etc correspond to the user. If you don't want to use supabase.js and PostgREST, this means you would need to implement this flow all by yourself
  • g

    gleki

    12/16/2021, 1:45 PM
    @chipilov 👍
  • g

    Gary, el Pingüino Artefacto

    12/16/2021, 7:01 PM
    hi, its there a way to do aggregate functions using supabase? like sum and avg
  • g

    garyaustin

    12/16/2021, 8:21 PM
    With the Postgres functions you can do any of the postgres aggregate functions and then use an rpc function to access those if needed. https://www.postgresql.org/docs/14/functions-aggregate.html
  • g

    Gary, el Pingüino Artefacto

    12/16/2021, 8:22 PM
    the rls rules are applied to the rpc functions?
    g
    • 2
    • 1
  • g

    Gary, el Pingüino Artefacto

    12/16/2021, 8:24 PM
    also i tried using a view, but the rls rules aren't applied there
  • j

    Jshen

    12/16/2021, 8:48 PM
    Hi, how are we supposed to make more complex queries? I want to insert a row into Table B and then update a row in Table A with the id of that new row. Currently, I'm just doing a insert and then a separate update but I want to combine it into a single query. Thanks
    g
    • 2
    • 3
  • g

    garyaustin

    12/16/2021, 8:48 PM
    RLS rules on rpc
  • m

    Mike92988

    12/17/2021, 3:23 PM
    Anybody know how I can set a column data type to be an incremental number that starts at a certain number i.e 10000?
  • j

    jensen

    12/17/2021, 6:14 PM
    You could use a Serial value and then set the sequence to start at 10000
  • j

    jensen

    12/17/2021, 6:16 PM
    Once you setup the table you can use
    select setval('column_serial_seq', 10000);
  • j

    jensen

    12/17/2021, 6:16 PM
    Depending on what the sequence gets called
  • j

    jensen

    12/17/2021, 6:19 PM
    this gives some examples http://sqlines.com/postgresql/datatypes/serial
1...272829...52Latest