Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL, add prefix to record field in SQL

Tags:

sql

postgresql

the problem is: is there a query in postgreSQL that will add some prefix to every record specific field? For example let's assume we have table users:

**id**    **name**
  1        adam
  2        ewa

and i want to get records and add to every id some specific prefix - let's say 'foo_', desirable result:

id: 'foo_1', name: adam
id: 'foo_2', name: ewa

I know it can be done with Python after retrieving records, but i wonder if possible with query.

Thanks in advance!!

like image 291
dahel Avatar asked Oct 18 '25 13:10

dahel


1 Answers

select 'foo_'||id::text,
       name
from the_table;