Postgres text type vs Go string type

Hi! Is there a particular way a Postgres column/field that is of type “text” needs to be updated in Go considering Go has data type “string”, but not data type “text”?

I’m writing tests on the CRUD functionality of my project, and the update test for a particular table, which updates a single field in a row, is returning an empty string for one of the fields/columns I’m not updating. I would expect the value of that field in the updated row to match that value in that row before the update.

Just wondering if it could have anything to do with Postgres text vs Go string.

Please publish your code…

Thanks for replying. After doing some digging, I’ve learned that text vs string isn’t my issue. In fact, there should be no issue at all between the two types.

I am using sqlc and it appears now that my issue likely lies in the way record updates are handled when multiple fields in a record are updateable, but only a subset of them need to be updated. I assumed that if a value wasn’t being passed for a particular field as part of the args in the update, then it would leave that field untouched, when in actuality, since I’m not providing a value, it apparently updates the field with its zero value, in my case an empty string.

I just posted a question in the sqlc github repository discussion to see what the proper way to handling this is. If no solution results there, I will post my code here.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.