I’m reading info from a pqsql database (and changed my engine from mysql)
there is something weird in the string data returned,
if the field length in the db is 50 chars the returned value has 50 chars length, so
even if the value in the db is inserted with fewer elements the returned value size is 50.
in mysql the returned value size was the same as it was inserted in the db.
example
create table values(data char(50))
insert into table values('info');
when i pick up this data with PQgetvalue
res=PQexec(conn,"select * from values");
printf(" the value has the lenght of %d chars",strlen(PQgetvalue(res,0,0)));
it will display
the value has the lenght of 50
im kinda surprised of this because now i need to store o calculate in some way the real size of the field, no the max field size
I’m doing something wrong?
(sorry for the typos)
The field is declared as char, not varchar. A char field’s value will always have the declared length, probably after padding the value from the right with spaces. From your description, I’d consider changing it to varchar.
See http://www.postgresql.org/docs/8.2/static/datatype-character.html