1

I want to combine the content of two columns and insert it into a new column.

But it does not work. Example:

create table car(
   id bigint NOT NULL,
   manufacture character varying(255),
   number character varying(255),
   result character varying(255)
)

insert into car (result)
select concat(manufacture, ' ', number) from car

Result:

ERROR:  NULL-Value in column „id“ error Not-Null-Constraint
DETAIL:  Failed line contains (null, null, null, bmw 123).

How can I just update the specific row, and leave all other values as it is?

6
  • I don't understand how this is related to Java. Commented Dec 2, 2014 at 10:51
  • sorry, yes it's not of course Commented Dec 2, 2014 at 10:52
  • Try SELECT COALESCE(col_a, '') || COALESCE(col_b, ''); Commented Dec 2, 2014 at 10:52
  • I think you actually mean to "update" rather than "insert". Update changes something about an existing row. Insert adds a new row. (assuming you want 1, bmw, 123, bmw 123) Commented Dec 2, 2014 at 10:56
  • What's your plan for situations where the number of characters in the manufacturer and number fields is more than 255? Commented Dec 2, 2014 at 10:56

1 Answer 1

3
update car set result = concat(manufacture, ' ', number)
Sign up to request clarification or add additional context in comments.

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.