Peter Eisentraut <peter.eisentr...@2ndquadrant.com> writes: > On 6/24/17 06:31, Dmitry Igrishin wrote: >> PQgetvalue returns a value of type char* (without const). But the >> documentation says: >> "The pointer returned by PQgetvalue points to storage that is part of >> the PGresult structure. /One should not modify the data it points to/" >> (my italics). Could someone tell me please, what wrong with modifing >> arbitrary character of the data pointed by PQgetvalue's returning value? >> Or why this restriction is documented? Thanks.
> This is just how the API is defined. It could be defined differently, > but it is not. To enlarge on that: it might well work today. But if we change the code in future so that it does not work, we will make no apologies. There's at least one case where you could have a problem today. All null entries in a PGresult share the same pointer to an empty string, so that if you were to modify that string, it would affect what's seen for other "null" values. If the API allowed modification of data values, that would be a bug. But it doesn't, and so it isn't, and we wouldn't look kindly on complaints about it. Ideally, PQgetvalue should be redefined to return "const char *". I don't really see us doing that anytime soon though. It would result in a lot of compile warnings for perfectly-safe client code. I'm sure this API would look different if it weren't older than universal availability of "const" :-( regards, tom lane -- Sent via pgsql-hackers mailing list (email@example.com) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers