0

I have a PostgreSQL data-table with following data

id    assignmentId    folderId    folderId_new
1     2274            5332
2     2274            5348
3     2274            5349
4     2274            5350
46    2277            5355
75    2275            5351
76    2275            5352
77    2275            5353
78    2275            5354
...

and columns datatype

id                serial
assignmentId      integer
folderId          text
folderId_new      integer

I want to save the values of folderId column to folderId_new column.
I have tried following queries

update framethreshold set folderId_new = CAST (folderId AS integer)

update framethreshold set folderId_new = folderId::int

but results in the error:

ERROR: invalid input syntax for integer: "" SQL state: 22P02
2
  • What errors were they showing? Commented May 20, 2016 at 11:12
  • ERROR: invalid input syntax for integer: "" ********** Error ********** ERROR: invalid input syntax for integer: "" SQL state: 22P02 Commented May 20, 2016 at 11:15

1 Answer 1

1

Ok, so you can write this query

update framethreshold set folderId_new = NULLIF(folderId, '')::int

hope this will work ;)

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.