• Blog posts

    Bio

    By David Crowther

    PostGIS___Replace_Values_in_a_Field_-_1.PNG

    Question:

    How do you replace values in a field in a PostGIS table?

    Answer:

    To replace a set of existing values with an alternate string of text, you can use an UPDATE statement.

    For example, you may have a field that contains the location of Image files (or PDFs etc…),. the field in this case is called – new_url.

    PostGIS___Replace_Values_in_a_Field_-_2.PNG

    In this example we wish to replace the reference to the C Drive and instead just have the name of the file e.g. B-R-2-5b.tif. To do this you can use the syntax below:

    PostGIS___Replace_Values_in_a_Field_-_3.PNG

    … here we have searched for a value PostGIS___Replace_Values_in_a_Field_-_4.PNG and replaced it with blank – using PostGIS___Replace_Values_in_a_Field_-_5.PNG

    The result will be that the new_url field is now updated to remove the location value, replacing it with ‘nothing’ and so you will be left with just the file name:

    PostGIS___Replace_Values_in_a_Field_-_6.PNG

    Another example could be that you wish to change the reference to the file from an IMAGE (.tif) to a DOCUMENT (.pdf)

    PostGIS___Replace_Values_in_a_Field_-_7.PNG

    … once ran, each record will now be referencing a .pdf instead of a .tif.

    PostGIS___Replace_Values_in_a_Field_-_8.PNG

Comments

0 comments

Please sign in to leave a comment.