0

I have two columns, material_size (text type) and material_size_temp (text[] array type).

When I ran UPDATE parts SET material_size_temp[0] = material_size; I would get values like [0:0]={".021 x 2.450"} instead of {".021 x 2.450"}.

How do I clone the text type column to text[] array type column?

  • Do you want to replace the existing value in material_size_temp (the whole array) or just the first element? Or do you want to prepend the array with the text from material_size? – Erwin Brandstetter Mar 17 '15 at 0:03
  • @ErwinBrandstetter Most rows have data (just a single measurement) and some no data. I was just trying to move the data in to an array. – John Mar 17 '15 at 14:47
1

I was close, unlike JavaScript and PHP it seems PostgreSQL array key numbers start with 1, not 0.

UPDATE parts SET material_size_temp[1] = material_size;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.