I have raster data in a postgis server (I am able to see it in qgis).
When I retrieve it and form gtiff image out of it using gdal, the generated image is not correct (there is a coloring problem).
I am able to retrieve the metadata correctly.

For raster I am doing `st_AsBinary(rast)`.
And then passing it to gdal raster io buffer parameter

Metadata is read first successfully. 
Image was stored as tiles

**Code:**

```
for(int row=0;row<99;row++){
int xoff,yoff;
        yoff=row*metadata.tilesizeY ;
        for(int col=0;col<99;col++){
              xoff=col*metadata.tilesizeX;
              query<<"select st_asbinary(rast) from public.tkptest where rid ="<<(row*99)+col+1;
              retval = PQexec(options.connection,query.str().c_str());
              res= PQresultStatus(retval);
              if(res!=PGRES_TUPLES_OK){
                    std::cout<<"We did not get any data\n";
                    return res;
              }
              dstDS->RasterIO(GF_Write,xoff,yoff,metadata.tilesizeX ,metadata.tilesizeY ,PQgetvalue(retval,0,0),metadata.tilesizeX *metadata.datasize,metadata.tilesizeY *metadata.datasize  ,metadata.dtype,metadata.numBands,panBandMap,0,0,0);
              PQclear(retval);
              query.clear();
              query.str("");

        }
}
GDALClose(dstDS);

```