I am trying to export some data from MATLAB to a database. I am using a PostgreSQL database through ODBC as follows. First, I create a connection:
dbConn = database('PostgreSQL30', username,password);
If I try to do some test insertion manually, everything will look fine:
exec( dbConn, 'insert into test(std) values(2.2)')
When I try to generate a short query dynamically, everything still looks fine:
q = sprintf('insert into test(std) values(%2.2f)', 12.345);
res = exec(dbConn, q);
But when I try to generate some query containing strings, I get an error message:
>> q = sprintf('insert into test(name) values("%s")', 'xxx')
q =
insert into test(name) values("xxx")
>> res = exec(dbConn, q);
>> res.Message
ans =
ERROR: column "xxx" does not exist;
Error while executing the query
It makes no difference if I use the format "%s"or regular %s. What is the problem?
EDIT
OK, I used the wrong quotation marks. When i use:
q = sprintf('insert into test(name) values(''%s'')', 'xxx')
everything is fine. Thus, the question can be closed / deleted. Sorry to bother you.