0

I have a table in postgresql called 'raw_data_file' and it has a 7 columns and the last one is called 'status' and consists of strings only.

I am trying to replace all instances of 'PASS1_SUCCEEDED' with 'S3UPLOAD_SUCCEEDED'.

Here is my code:

select status from raw_data_file;

UPDATE raw_data_file 
  SET status = replace (status, 'PASS1_SUCCEEDED`', 'S3UPLOAD_SUCCEEDED'); 

For some reason, I am getting the error:

Error occurred during SQL query execution

Reason:
SQL Error [42883]: ERROR: function replace(raw_data_file_status_e, unknown, unknown) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 35
Error occurred during SQL query execution

Reason:
SQL Error [42883]: ERROR: function replace(raw_data_file_status_e, unknown, unknown) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 35

Any ideas what is causing this and how I can fix it?

1
  • What data type exactly is the status column? It seems that status is an enum, not a text (or varchar) column. Commented Aug 9, 2022 at 10:04

1 Answer 1

1

As error hints, try explicit casts:

UPDATE raw_data_file SET status = replace (status, 'PASS1_SUCCEEDED'::text, 'S3UPLOAD_SUCCEEDED'::text);

Btw, if your status field always contains only ONE of these text (so it cant contains things like PASS1_SUCCEEDED;PASS2_SUCCEEDED, you dont need string replace, you can simply do

UPDATE raw_data_file SET status = 'S3UPLOAD_SUCCEEDED' WHERE status = 'PASS1_SUCCEEDED';
Sign up to request clarification or add additional context in comments.

2 Comments

Awsome thanks- your second point has saved me a lot of time :)
For me, explicit types helped with this error because it lead to a new error where I hadn't noticed my deeply nested functions were missing a comma. (Specifically, a comma after the closing parens of an inner replace function and before the outer replace function's other arguments).

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.