[postgis-users] PostGis introduction doc code block seems wrong....

Paul Ramsey pramsey at cleverelephant.ca
Thu Apr 21 08:32:51 PDT 2022


Well now that you mention it, it does seem funky, and I have no idea what the expected behavour is...

create table foo (old text, new text);

insert into foo (old) values ('1234');

update foo set old = left(old, 2), new = old
where old = '1234';

select * from foo;

I'm going to go out on a limb and suggest that maybe the values on the right-hand side of the assignment are actually always implicitly from the original record, so in trigger terms, the assignments look like NEW.colname = OLD.colname.

P


> On Apr 21, 2022, at 2:12 AM, Bo Victor Thomsen <bo.victor.thomsen at gmail.com> wrote:
> 
> Am I the only one that get "semantic itch" looking at the UPDATE expression? I would prefer it like this:
> 
> UPDATE nyc_neighborhoods
>   SET geom_invalid = geom,
>       geom = ST_MakeValid(geom)
>   WHERE NOT ST_IsValid(geom);
> where you save the original "geom" value into another column "geom_invalid" before rectifying it and saving it into the original column.
> 
> Disclaimer: I have no clue about the internal methods of the SQL interpreter and how and in which order it assigns values.
> 
> Med venlig hilsen / Kind regards
> 
> Bo Victor Thomsen
> 
> Den 20-04-2022 kl. 16:59 skrev Regina Obe:
>> Thanks for the errata.  Corrected now.
>>  
>> From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Jian He
>> Sent: Wednesday, April 20, 2022 5:12 AM
>> To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
>> Subject: [postgis-users] PostGis introduction doc code block seems wrong....
>>  
>>  
>> 23. Validity — Introduction to PostGIS
>> last code block, 
>> -- Fix invalid and save the original
>> UPDATE nyc_neighborhoods
>>   SET geom = ST_MakeValid(geom),
>>       invalid_geom = geom
>>   WHERE NOT ST_IsValid(geom);
>>  
>> I think it should be:
>> -- Fix invalid and save the original
>> UPDATE nyc_neighborhoods
>>   SET geom = ST_MakeValid(geom),
>>       geom_invalid = geom
>> 
>>   
>> WHERE NOT ST_IsValid(geom);
>>  
>> 
>> 
>> _______________________________________________
>> postgis-users mailing list
>> 
>> postgis-users at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/postgis-users
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users



More information about the postgis-users mailing list