Question: I am using ibpy to get my porfolio information every 10 seconds (i need this information in a very frequent manner), specifically the unrealized pnl information for each contract. The way i do it is :

```
def updatePortfolio(self):
    self._portfolio=[]
    if self._updated_accounts==False:
        print("requesting account updates")
        self._tws.reqAccountUpdates(True,'')
        sleep(3)
        print("requesting account value updates")
        self._tws.updateAccountValue()
        sleep(3)
        print("requesting portfolio updates")
        self._tws.updatePortfolio()
        sleep(3)

```

However, since I do this pretty frequently (every 10 second). It seems portfolio information is not sent back and it usually leads to empty portfolio. How do i ensure that I could request and refresh the portfolio information and not its update (meaning that i should get the complete portfolio information each time i request)? Thank you.

Answer: 
You can easily convert to and from `bytea` and `text`, like this

```
SELECT convert_from('foo'::bytea, 'UTF8');

```

However, I don't think that's relevant.

You're using the [`serailize()` function of php](http://php.net/manual/en/function.serialize.php)

> 
> Note that this is a binary string which may include null bytes, and needs to be stored and handled as such. For example, `serialize()` output should generally be stored in a `BLOB` field in a database, rather than a `CHAR` or `TEXT` field.
> 
> 
> 

That function returns binary data. And likewise, `unserialize()` *expects* binary data. If you don't want to use binary data in the php, you can make `jobs.jobinfo` a `jsonb` type and send the result of `json_encode()` to it, and then `json_decode()` from it..

* <http://php.net/manual/en/function.json-decode.php>
* <http://php.net/manual/en/function.json-encode.php>
This code retrieved the serialized string from the contents of the postgres ByteA field:

`$serializedString = pg_unescape_bytea($contentsOfPostGresByteAField);`

Thanks to [Sergey Pashkov](http://valentina-db.com/en/discussion-forums/2727-moving-from-mysql-postgres-best-way-to-store-php-objects-in-mysql,-retrieve-in-postgres#reply-2741) for the tip!