Re: How to always run UPDATE FROM despite missing records in thesource table? - Mailing list pgsql-general

From Alexander Farber
Subject Re: How to always run UPDATE FROM despite missing records in thesource table?
Date
Msg-id CAADeyWjFNLPDqjuLhX0hr1i-VTpyAqTNiPs4V6__YAvT-LabeQ@mail.gmail.com
Whole thread Raw
In response to Re: How to always run UPDATE FROM despite missing records in thesource table?  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: How to always run UPDATE FROM despite missing records in the source table?
List pgsql-general
Thank you Adrian -

On Fri, Jan 11, 2019 at 4:55 PM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 1/11/19 4:50 AM, Alexander Farber wrote:
> https://www.db-fiddle.com/f/22jfWnsvqD8hVeFPXsyLbV/0

Why not put a test for the block in the function and then use different
UPDATE's depending on the result?

I didn't want to use IF and switch that statement to PL/pgSQL from pure SQL, so Andrew's answer

 UPDATE users u SET 
    visited = now(),
    ip = v.ip,
    lat = i.lat,
    lng = i.lng
FROM (VALUES ('20.20.20.20'::inet)) v(ip)
      LEFT JOIN geoip i ON (v.ip <<= i.block)
WHERE u.uid = 2;

suits me better, even though I wonder what is the (VALUES ('20.20.20.20'::inet)) v(ip) construct there, some temporary table which is then LEGT JOINed to the geoip table?

Also, Andrew you have been right - with spgist index my queries against geoip are fast enough, I was looking at the wrong spot in my EXPLAIN ANALYZE output (the average values are slow, I am going to cache them soon)

Regards
Alex

pgsql-general by date:

Previous
From: Pratik Parikh
Date:
Subject: Re: Static PostgreSQL Binaries (Linux + Windows)
Next
From: Andrew Gierth
Date:
Subject: Re: How to always run UPDATE FROM despite missing records in the source table?