Also you posted this in
https://groups.google.com/forum/#!msg/django-developers/r7JP_YHsIhM/jmof68XFBAAJ
. Please don't repost, keep the conversation in one place.

On 3 October 2017 at 17:00, Aymeric Augustin <
[email protected]> wrote:

> Hello,
>
> Since I haven't seen positive feedback from a committer, I'm not convinced
> there's consensus about this change.
>
> Also this doesn't look like a particularly easy topic for a beginner. It
> raises the following questions:
>
> - INSERT ON CONFLICT UPDATE would likely be a better option on Postgres ≥
> 9.5, wouldn't it?
> - what about other databases with built-in backends? third-party backends?
> - is this implementation really appropriate at any isolation level?
> - what are the consequences for performance?
>
> Best regards,
>
> --
> Aymeric.
>
>
> 2017-10-03 17:23 GMT+02:00 Дилян Палаузов <[email protected]>:
>
>> Hello Muhereza,
>>
>> I assume you understand by now Django quite well and are willing to give
>> something "in return".
>>
>> Currently QuerySet.get_or_create() consists of two SQL commands: SELECT +
>> optional INSERT.  They cause a concurrent problem, if another
>> get_or_create() is called between the SQL statements.
>>
>> With the Postgresql backend it is possible to reduce the queries to a
>> single one.
>>
>> Consider this table:
>>
>> CREATE TABLE t (
>>    id SERIAL PRIMARY KEY,
>>    name VARCHAR(10) NOT NULL UNIQUE,
>>    comment VARCHAR(10));
>>
>> The following query can do what get_or_create() currently achieves:
>>
>> WITH
>>   maybe_found AS (SELECT * FROM t WHERE t.name='nameD'),
>>   to_be_inserted AS (SELECT 'nameD' as "name", 'comment13' as "comment"),
>>   just_inserted AS (
>>          INSERT INTO t (name, comment) SELECT * FROM to_be_inserted
>>                         WHERE NOT EXISTS(SELECT * FROM maybe_found)
>>          RETURNING *)
>> SELECT *, FALSE as "created" FROM maybe_found UNION ALL
>> SELECT *, TRUE AS "created" FROM just_inserted LIMIT 2;
>>
>> where "to_be_inserted' contains the values for the new object ('default'
>> parameter of get_or_create) and 'nameB' in maybe_found is the criterion
>> passed to get().
>>
>> The challenge is to integrate the WITH ... SELECT query in Django.  As
>> guidance I can only suggest looking at the existing code.
>>
>> Regards
>>    Дилян
>>
>>
>> On 10/03/2017 10:24 AM, Muhereza Herman wrote:
>>
>>> Hello, anyone reading this please help me out.
>>> am a new developer but i would like to contribute to_*django*_.
>>> please guide me on how to do that. thank you.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django developers (Contributions to Django itself)" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <mailto:
>>> [email protected]>.
>>> To post to this group, send email to [email protected]
>>> <mailto:[email protected]>.
>>> Visit this group at https://groups.google.com/group/django-developers.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-developers/e6d798ac-4ede-45c4-9f20-ca62f0595131%4
>>> 0googlegroups.com <https://groups.google.com/d/m
>>> sgid/django-developers/e6d798ac-4ede-45c4-9f20-ca62f0595131%
>>> 40googlegroups.com?utm_medium=email&utm_source=footer>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers  (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-developers.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-developers/062e270c-85f6-23a5-64a3-b225ddcff3ab%40aegee.org.
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-developers/CANE-7mVgudhd0wDAvX9_uLxFUJ89w2Lge6-0rOh_
> U3hPCc4WnA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CANE-7mVgudhd0wDAvX9_uLxFUJ89w2Lge6-0rOh_U3hPCc4WnA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1DcuhCOpWd1%3DpVv5TQBh960UL8M68bnO6tFDhjPx-L%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to