views:

134

answers:

1

hello i have i want to do something like this.

i have 4 rows with unique id 1,2,3,4 all four rows contains some string like option1,option2,option3,option4

now i want to add "a ) " to the option1, "b ) " to the option2 and so on so is there a way i can do this with a query.currently i am adding these to a lots of rows manually

+1  A: 

It's not clear exactly by what logic you want to select the letter to prepend to field somestring, but if for example it's a "Caesar's cypher" (1 gives 'a', 2 gives 'b' etc) based on the id field, as your question suggests, then this should work:

UPDATE sometable
SET somestring = (
  substr('abcdefghijklmnopqrstuvwxyz', id, 1) ||
  ' ) ' || somestring)
WHERE id <= 26;

...for no more than 26 rows of course, since beyond that the logic must change and obviously we can't guess just how you want to extend it (use id modulo 26 + 1, use more characters than just lowercase letters, or ...?) since you give no clue on why you want to do this.

Alex Martelli