Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

chdb generates warnings when trying to store arrays as values. #1

Closed
zyxist opened this Issue · 3 comments

2 participants

@zyxist

I tried to store an array as the value in the chdb. It is not said that I can't, and this is something I needed. Unfortunately, chdb thrown lots of warnings "Array to string conversion" when saving the array with chdb_create(). I think that automatic serialization of compound data types would be very useful feature.

The problem is that chdb would have to remember which values are serialized and which ones are not in order not to unserialize an ordinary string by accident.

If this feature is not going to be added, it should be clearly marked that the array values must be scalar types and chdb_create() should fail immediately when something is going wrong.

@lcastelli
Owner

CHDB only supports strings (binary as well) for data. This is mentioned at http://php.net/manual/en/function.chdb-create.php in the description of the parameter 'data'.

The automatic conversion of the parameters to strings is done to follow the somewhat loosely typed model that is used (and probably expected) in general in PHP. For example this allows storing integer and floating point numbers in CHDB without doing an explicit conversion.

I wouldn't go further than basic casting to string though, as full fledged serialization is a complex issue with several alternatives. I think that the choice of how to do that is better left to the client, instead of hard-coding it in the library.

@lcastelli lcastelli closed this
@zyxist

OK, thanks for the information. However, after your comment I'm concerned about other problem. You have mentioned that floats are converted to strings, too, but this process can lead to the potential loss of the information, as binary and decimal floating point notations are not equivalent, and furthermore the conversion is vulnerable to the rounding issues.

@lcastelli
Owner

Yes, I'd say that in general you lose all the information that arises with PHP conversions to strings.

That is you always lose the original type of the data, with floats you can get slightly different values back, and with arrays and objects you basically lose everything (and get warnings).

The point is, CHDB is really all about storing sequences of bytes, which in the PHP world are represented with (binary) strings. This is the most general approach.

When CHDB is given values that are not directly strings, it behaves the way that I feel is what is generally expected in PHP: it does a simple type cast and goes on. Had it been Python I would have probably made it throw an exception, but I don't think that would be very much in line with the rest of the PHP world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.