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/msgid/django-developers/e6d798ac-4ede-45c4-9f20-ca62f0595131%40googlegroups.com
<https://groups.google.com/d/msgid/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/msgid/django-developers/062e270c-85f6-23a5-64a3-b225ddcff3ab%40aegee.org.
For more options, visit https://groups.google.com/d/optout.