4

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!!

1

2 Answers 2

2
select 'foo_'||id::text,
       name
from the_table;
Sign up to request clarification or add additional context in comments.

Comments

2

You can just use a concatenation operator String Functions and Operators

SELECT 'foo_' || id::text FROM table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.