2

I have a table like this:

+-----+------------+-------+--------+-----------+
| ID  |  val1      | val2  | val3   |  array_3  |
+-----+------------+-------+--------+-----------+
| 100 |  110       | 25    | 53     |{110,25,53}|
| 101 |  56        | 75    | 59     |{56,75,59} |
| 102 |  65        | 93    | 82     |{65,93,82} |
| 103 |  75        | 70    | 80     |{75,70,80} |
+-----+------------+-------+--------+-----------+

imagine I have the values for ID, val1, val2 and val3 columns and I want the resulting array in the array_3 table which is an array type and its size is 1*3. How can I do that?

2 Answers 2

2

Array constructor?

http://sqlfiddle.com/#!12/c297a/

SELECT "ID", ARRAY[val1,val2,val3], array_3
FROM table1;

To put the output in a separate table use CREATE TABLE .. AS.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, already informative. but my array_3 column is empty now and I want to fill it with the values like that I've already out in the table.
@f.ashouri Then use the array constructor in an UPDATE. It was hard to tell exactly what you were wanting to do with it.
2

update mytable set array_3=ARRAY[pix_val1, pix_val2]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.