Lucky
@bonbot had more features, so user tried them out.
But this bot only acts on links of files on github, and that's all.
I don't really think it spams, as it makes github links future-proof, adding just a single line.
If you try to access a link later it's always work to find the right commit, at the right day.
Alexander
Ok, sounds good
Lucky
Sorry, you meant to add @PermalinkBot.
@bonbot is the spammy multi-purpose bot.
Lucky
My mistake. I was not clear above. Sorry. @PermalinkBot it is.
Alexander
No problem )
Yurii
Hi, @akozlovsky .
I have one question.
Сan you explain briefly how list comprehensions is being translated into sql?
Alexander
Hi, I described some steps here:
https://stackoverflow.com/questions/16115713/how-pony-orm-does-its-tricks/16118756#16118756
Yurii
Wow, thanks.
ichux
I just got honored by the PSF.
Alexander
Congratulations!
ichux
Alexander
Happy New Year!
Henri
🥂
Artur Rakhmatulin
🎄
Claudio
🥂
Joery
Matthew
Hi,
I have a bunch of queries like this in my postgres slowlog:
2018-01-01 10:03:38 UTC LOG: duration: 1863.315 ms statement: INSERT INTO "x" ... VALUES ... RETURNING "id"
Matthew
they all seem to happen in the same time in batches
Matthew
as far as i can tell, there is nothing special about the insert or the table
Matthew
could the "returning id" be causing the queries to have to wait for each other?
Matthew
Should I use db.insert https://docs.ponyorm.com/api_reference.html#Database.insert for this?
Matthew
I am doing a few million inserts of this object per day
Alexander
Happy New Year to all!
Hi Matthew, I think the long insert time may be caused by waiting for some concurrent transaction to finish, for example if that another long-running transaction updated some index, and insert command needs to update that index too. I don't think RETURNING ID clause can slow down the query. Also, I doubt db.insert method may help here - its benefit is that the object is not created in Python before insert, so we can avoid Python overhead when doing millions of inserts. But in your case the slowdown is happened in database and not in Python
Matthew
Aha! Almost immediately after this insert, I do a commit(), so it looks like that could be the case
Christian
Hi there. Happy new year. This is my last resort, i've been trying for hours to find out how to simply create or update a pony database. i poll data from a game, i want to update the entry if it exists, otherwise update it. i got as far as creating it, but i get one error after another when trying to update it, i get "TypeError: float() argument must be a string or a number" for example, even if the value in the db field IS float and the value i'm writing in there is a hardcoded 1.4 or float(100). if i simply skip that line, the same error happens with every other item
Christian
is there anyone who can point me in the right direction?
Christian
seriously, this
Christian
test = int(player_data.group(1))
db_player.id = test,
Christian
fails with
Christian
TypeError: Value type for attribute Player.id must be int. Got: <type 'tuple'>
Christian
the content od test is 710
Alexander
Christian
OMG. that's what comes from hours of staring at code and not drinking enough. with all that converting from this to that i totally forgot about those :(
Christian
i had the data stored in a dict before i wanted to switch to orm...
Christian
it works now. you saved my sanity
Christian
THANK YOU ❤️
Christian
and sorry for being such a dumbass ^^
Alexander
No problem :)
Juan Antonio
Is there an "update if exists, add if not" (like the one in MongoDB) in PonyORM?
Juan Antonio
Nice, thank you
Lucky
Alexander
yes
Anonymous
I see there is some interest in get_or_create (https://github.com/ponyorm/pony/issues/131) and that it somehow relates to upsert? I wrote this a while back but I assume it's wrong - can anyone say why?
def get_or_create(PonyEntity, defaults=None, **kwargs):
created = False
# Try get the object with the kwargs passed in
result = PonyEntity.get(**kwargs)
if result is None:
# Update kwargs with defaults
kwargs.update(defaults)
result = PonyEntity(**kwargs)
created = True
return result, created
Matthew
I think it's because of this:
Matthew
Matthew
race condition
Anonymous
Ah - ok I see. So if I'm not parallelising my accesses to those parts of the DB, the code I wrote should be fine to include in some utils.py?
Matthew
Yes
Anonymous
😅
Anonymous
Thanks
Matthew
Lucky
This is really a missing feature for such a commonly use case
Alexander
I agree, we need to add it
Lucky
As far as I know mysql can do it and so can postgres
Matthew
I am trying to find the previous sunday from a given date, this code works but seems inelegant, is it possible to do this without a for loop or list comprehension?
Matthew
for i in range(8):
last_sunday = today - datetime.timedelta(days=i)
if last_sunday.weekday() == 6 and last_sunday != today:
break
Juan Antonio
Check SO: https://stackoverflow.com/questions/18200530/get-the-last-sunday-and-saturdays-date-in-python
Matthew
ah the modulus is clever, thanks!
Matthew
In [4]: select(r for r in Result if between(datetime.date(2010, 1, 1), r.date, datetime.date(2020, 1, 1))).count()
...:
...:
SELECT COUNT(*)
FROM "result" "r"
WHERE '2010-01-01' BETWEEN "r"."date" AND '2020-01-01'
Matthew
def between(a, x, y):
return a <= x <= y
Matthew
It seems like the order of the arguments does not correlate?
Alexander
Oops, you are right...
Alexander
Fixed
Lucky
Lucky
The best would probably be
r.date.between(x,y)
Alexander
between cannot be method of date, because it used with other types as well. I changed its signature to between(x, a, b), and the python implementation is
def between(x, a, b):
return a <= x <= b
It was already implemented this way inside Python -> SQL translator, so queries work the same way as before
Matthew
That makes sense thank you
Александр
Hi! I am learning to program. I asked ru.stackoverflow. You reply in Russian?))
https://goo.gl/t7Ef3y
Alexander
I can reply in a hour
Александр
It is not urgent! Thank you so much!!!
Matthew
Is there any reason to choose psycopg2cffi for a new project?
Anonymous
Edwin
hi :)
Lucky
Actually why is
r.date in range(x,y) not supported?
Alexander
Alexander