News for hackers. Stuff that matters.
Re:What ORMs have taught me: just learn SQL by terhechte on Monday August 04, 2014 @06:32PM (#8134439)
Postgres indeed doesn't have Upsert yet, so I'm going the default way of locking the table, and implementing it via a slightly more complex query. I was just too lazy to explain that in my earlier comment. The problem is the same: The syntax below can't really be represented well in a ORM.

    BEGIN;
    LOCK TABLE search_tracking IN SHARE ROW EXCLUSIVE MODE;
    WITH upsert AS (UPDATE search_tracking SET count=count+1 WHERE keyword = 'John Doe' RETURNING *) INSERT INTO search_tracking (keyword, count) SELECT 'John Doe', 1 WHERE NOT EXISTS(SELECT * FROM upsert);
    COMMIT;
Re:What ORMs have taught me: just learn SQL by jimktrains2 on Monday August 04, 2014 @07:13PM (#8134595)
You can use writable CTEs as an upsert in postgres. http://dba.stackexchange.com/questions/13468/most-idiomatic-...
Re:What ORMs have taught me: just learn SQL by NicoJuicy on Tuesday August 05, 2014 @05:07AM (#8136098)
But this aint that hard, i suppose it could also be done in Postgres (query using MS SQL Server)

Table1 SET (...) WHERE Column1='SomeValue'

IF @@ROWCOUNT=0

    INSERT INTO Table1 VALUES (...)
Re:What ORMs have taught me: just learn SQL by _ZeD_ on Tuesday August 05, 2014 @07:59AM (#8136442)
not atomic
Re:What ORMs have taught me: just learn SQL by sk5t on Tuesday August 05, 2014 @12:26PM (#8137748)
Thus transactions...