Get returning columns (mostly primary key) on bulk upserts with GUI queries

  • Goal:

I would like to get the affected (inserted) identifier rows when using upsert with "Bulk upsert via a primary key" queries and similar that are created via GUI. While I can get this result writing the sql query myself, this is highly inconvenient.

Thank you.

  • Steps:

  • Details:

In case of "Bulk upsert via a primary key" I would expect to include "returning primary key column" at the end of the query, so I can get those IDs and work with them.

I don't want to write and maintain queries like this:
INSERT INTO
ec_products (
id,
brand_id,
name,
picture_url,
category_id,
description,
price
)
VALUES
(
coalesce(
{{ productId.value }},
nextval ('ec_products_product_id_seq')
),
{{ form2.data.brand_id }},
{{ form2.data.name }},
{{ form2.data.picture_url }},
{{ form2.data.category_id }},
{{ form2.data.description }},
{{ form2.data.price }}
) ON CONFLICT (id) DO
UPDATE
SET
picture = EXCLUDED.picture,
brand_id = EXCLUDED.brand_id,
name = EXCLUDED.name,
picture_url = EXCLUDED.picture_url,
category_id = EXCLUDED.category_id,
created_at = EXCLUDED.created_at,
description = EXCLUDED.description,
price = EXCLUDED.price,
updated_at = EXCLUDED.updated_at

RETURNING id;

2 Likes

Hi @mpezonadadttl,

Thanks for reaching out! What resource are you primarily working with?

1 Like

Hi Tess, thanks for your time.
I'm working with Retool Database.

Maybe this could be implemented as an additional input in the "advanced" tab, a checkbox, and return the same field that was specified in the text field "primary key column" or a different input, like multiple multiple inputs used for WHERE conditions.

As a side note, I want to say that I'm enjoying Retool so far.
Happy Christmas for all of you.

3 Likes

Happy holidays! Glad to hear you're enjoying Retool :blush:

I'll follow up if our team prioritizes this feature request

1 Like