Skip to content

Enable insert_and_get to work even when not using on_conflict #109

Open
@rvinzent

Description

@rvinzent

I have an insert query where I would like to have the database generate some field using a sequence. At the moment, Django does not return the generated field from the database by default, so I would like to use insert_and_get to add an additional (or all) fields to the RETURNING clause of my insert statement.

I don't need any special on_conflict behavior, I would just like to return the database generated field and have Django properly update the model field instead of only returning the pk.

It appears that the insert_and_get method is not exposed by PostgresManager. Is there any reason I must use on_conflict to get the entire row returned?

To clarify, I would simply like to execute

INSERT INTO my_table (some_field, another_field) VALUES (something, something_else) RETURNING *;

and have the Django model be updated appropriately.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions