Reputation: 721
Can i insert multiple values from different columns in one?
i have:
ref | alt | couple_refalt
--------------------------
A C AC ( i want)
A G AG Etc...
Is there a simple way?
I tried with:
INSERT INTO refalt(couple_refalt)
SELECT ref||alt
FROM refalt
WHERE ref='A';
Is it correct?
But it gives me the error:
null value in column violates not-null constraint
Postgres want a value for each colum, why can't i update or insert into specific column?
Upvotes: 0
Views: 53
Reputation: 1269533
Storing comma separated value is not the SQLish way to store values. What you seem to want is a computed column. Postgres does not support that directly. One method is to declare a view:
create view v_refault
select r.*, ref || ',' || alt
from refault;
Other possibilities are:
Upvotes: 1
Reputation: 1217
In order to insert two values into one column, you need to concatenate them. In postgresql the syntax is the following.
SELECT ref::text || ', ' || alt::text FROM refalt
If you want more details, here is the string documentation
Upvotes: 0