0

I'm updating an array by adding a varchar to an int4 array. The 'varchar' field is all numbers so I tried casting it to ::integer but it isn't working

update dwh.attr_lookup set kli_tree = array[target_909_kli::integer] || kli_tree

is giving me this error

ERROR: ERROR: invalid input syntax for integer: ""

Query = update
dwh.attr_lookup set kli_tree = array[target_909_kli::integer]
|| kli_tree

What is the proper way to do this?

2 Answers 2

2

You're trying to cast an empty string to an integer and that doesn't work:

=> select ''::int;
ERROR:  invalid input syntax for integer: ""
LINE 1: select ''::int;
               ^

You'll have to decide what you want to do with empty strings. If you want to convert them to zeros, then something like this should work:

array[case when target_909_kli = '' then 0 else target_909_kli::integer end]
Sign up to request clarification or add additional context in comments.

Comments

1

Obviously your varchar field is not all numbers. There would not be any double quotes in this case - as the error message informs us.

Try giving a full example if the error has not clear by now. Including table definition and sample values.

1 Comment

Actually it means that the OP is trying to cast an empty string, not a string with double quotes.

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.