Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a table with three columns. Column1 is id. Column2 is filename. Column3 is location. I need to write a query that will take all files with filename = X and will replace part of the string for 'location' lets say location = '/home/AAA/bin' and it will replace it with '/home/BBB/bin'. The start of location is always the same but the end is not always the same. I mean it will always start with /home/AAA/ but the end of the location is different for every file - /bin/ could be /somethingelse/.

share|improve this question
What did you try so far? What problems did you encounter? – Olaf Jun 6 '12 at 18:17

1 Answer

up vote 1 down vote accepted

You need to use this Postgres function

overlay(string placing string from int [for int]) 
ex: overlay('Txxxxas' placing 'hom' from 2 for 4)

Your situation involves the select statement having the following:

overlay(location placing '/home/BBB' from 1 for 9)

You can get more information from here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.