stof error using fetch with postgresql connection on ubuntu

2 views (last 30 days)
I'm having a strange and difficult to reproduce error fetching data from my postgre database using the native interface.
I can fetch my (quite large) dataset fine running in a windows 10 environment, however when using Ubuntu 20.04 (eithier bare metal, or in a docker container running a customerised version of the offical image) I get the following error: 'stof'. It's in red and absolutely no further explentation is provided. Google has not been my friend (appearently it's a function in the C++ 11 standard libary?, not sure that helps).
It's hard to provide code to reproduce it without my data, but it happens here:
% journeyId is a number, dbConn is a postgresql connection
%SamplesAndData is quite a wide view, which oftern has a lot of null
%columns
q = sprintf('SELECT * FROM public."SamplesAndData" WHERE "Journey" = %d', journeyId);
rawData = fetch(dbConn, q); %exception here
I've tried breaking the import into chunks and confusingly it doesn't always happen on the same row in the database, however it does almost always happen. With small enougn datasets (journeyId's in this example) it sometimes works.
I've tried the databaseDatastore as an alterntive, with the same results.

Answers (1)

Chris Morris
Chris Morris on 29 Jun 2023
To answere my own question (having worked on it all day yesterday, without sucess) the answere is:
Cast the fields I'm importing as numeric in the sql query.
Context: My data is stored in postgres as a mix of types, including both numeric and double. These were all (rightly) being imported into doubles in matlab, as should by databaseImportOptions. It was something of a leap in the dark, but my sql now looks like this:
'SELECT "Journey", "SystemTime", "PacketTime", "Tacho", "TrainSpeed" ,
"GNSS_SmpsSincePrev", "GNSS_SolTime", "GNSS_Lat"::NUMERIC , "GNSS_Lng"::NUMERIC, "GNSS_EllipHeight", "GNSS_MSLHeight", "GNSS_Speed", "GNSS_HAccuracy", "GNSS_VAccuracy", "GNSS_SAccuracy",
"GNSS_ValidFlags", "GNSS_FixType", "GNSS_SmpStat",
"BogieIMU_AccX"::NUMERIC, "BogieIMU_AccY"::NUMERIC, "BogieIMU_AccZ"::NUMERIC, "BogieIMU_GyroX"::NUMERIC, "BogieIMU_GyroY"::NUMERIC, "BogieIMU_GyroZ"::NUMERIC, "BogieIMU_SmpStat",
"BodyIMU_AccX"::NUMERIC, "BodyIMU_AccY"::NUMERIC, "BodyIMU_AccZ"::NUMERIC, "BodyIMU_GyroX"::NUMERIC, "BodyIMU_GyroY"::NUMERIC, "BodyIMU_GyroZ"::NUMERIC, "BodyIMU_SmpStat"
FROM public."SamplesAndData"
WHERE "Journey" = %d'
and it works. Note that I've only cast those fields that were stored in postgres as doubles.
It fields like some weird bug in the native postgres libary, but any future readers now know as much as I do!

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!