1

I'm very new to Matlab and I'm trying to update a cell into a Postgresql table.

This is my code

s=size(o,1);

for n=1:1:s

colnames={'obj_state_new'};
data = {num2str(2)};
tablename = 'objects';    
whereclause = ['WHERE obj_name = "obj', num2str(n), '"']
update(conn,tablename,colnames,data,whereclause)
end

But all I get is this error:

Error using database/update (line 268) Java exception occurred: java.sql.BatchUpdateException: Batch entry 0 UPDATE objects SET obj_state_new = '2' WHERE obj_name = "obj1" was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)

Error in scriptingTest (line 18) update(conn,tablename,colnames,data,whereclause)

I tested the connection and it's OK.

Can someone point me in the right direction?

Thanks in advance

0

1 Answer 1

2

UPDATE objects SET obj_state_new = '2' WHERE obj_name = "obj1"

The problem are the double quotes around the value.

String literals need to be enclosed in single quotes. Double quotes are for identifiers.

So the resulting where clause should look like this:

where obj_name = 'obj1'

not where obj_name = "obj1"

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.