wanted some advice on querying the database. If I ...
# help
s
wanted some advice on querying the database. If I want to get a record that has foreign keys and fold the inner-joined data in the response, is there a nice way to do this? I'm assuming I need to use a function, but not sure what the return type is if I have all the additional data present in the SELECT
n
Hello @stukennedy! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
If you want to return a setof rows, but have extra columns you set up a return table. https://www.geeksforgeeks.org/postgresql-function-returning-a-table/ This was someone's example of using an existing table row definition and adding to it. I've not tested it.
Copy code
CREATE OR REPLACE FUNCTION get_user(p_user_id uuid)
    RETURNS TABLE
            (
                users_row       public.users,
                ewkb_location text
            )
s
thanks so much ... exactly what I need