I would like to append some text to every cell in each column of my table to act as a symbol for that particular column. For example say my table is as follows (all fields are type character varying):
name age location james 45 france simon 33 usa ben 76 china
I would like to modify it to be:
name age location ajames b45 cfrance asimon b33 cusa aben b76 cchina
Does anyone have any suggestions as to how I can do this?
First you have to transform your age to be some kind of string. After that you can transform the values like this (of course you have to do this for each field):
update mytable set name = 'a' || name, age = 'b' || age;
This updates the data inside your table. If you only want the output to be prefixed you can use the following approach:
select 'a' || name as name, 'b' || age as age from mytable;
In this case there is no need to convert your age data type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With