Re: bytea question - Mailing list pgsql-general

From mikeo
Subject Re: bytea question
Date
Msg-id 3.0.1.32.20000816090451.00931c60@pop.spectrumtelecorp.com
Whole thread Raw
In response to Re: bytea question  (mjp@ornl.gov)
List pgsql-general
thanks,  i already have a perl script that splits based on
the backslash.  guess i'll just stick with that.  thanks for
you time and suggestions.

mikeo


At 06:06 PM 8/15/00 -0400, mjp@ornl.gov wrote:
>Oops! You have to write a function for it.  Here is a
>sample quick C function:
>
>typedef struct
>{ int   len;
>  char  data[1];
>} string;
>
>string *byteatostr(bytea *arg)
>{
>        char buf[1024];
>        int ln,i;
>        string *res;
>        ln = VARSIZE(arg) - VARHDRSZ;
>        memmove(buf, VARDATA(arg), ln);
>        for(i=0; i < ln; i++)
>         if( buf[i] < 32 ) buf[i]='?';
>
>        res = (string *) palloc(VARHDRSZ + ln);
>        memset(res, 0, VARHDRSZ + ln);
>        res->len = VARHDRSZ + ln;
>        memmove(res->data, buf, (int) ln);
>        return res;
>}
>
>where all non-printable chars are replaced with '?'. Optionally,
>the chars can be escaped (prefixed with '\') - adjusting ln as neccessry.
>
>
>now you get:
>
># select byteatostr(col) from test2;
>
>                         byteatostr
>------------------------------------------------------------
> fk_uste_wu_id?us_states?web_users?UNSPECIFIED?wu_id?wu_id?
>(1 rows)


pgsql-general by date:

Previous
From: Andrew McMillan
Date:
Subject: Re: Interval examples
Next
From: Andreas Tille
Date:
Subject: Is this the wrong list?