On Wed, 3 Sep 2003, Chris Boget wrote:

> > You can try
> > select CAST(cast('0000000000000000000000004' as NUMERIC(20)) AS varchar);
> 
> noobie question:
> 
> Do multiple casts like that slow down the query (in general and not specifically
> for the query above)?  If not, what about if the query is complex?

I don't know. This is simple solution. You can write UDF in c if qwery 
will be slowly, like this?

PG_FUNCTION_INFO_V1 (ztrim);
Datum ztrim(PG_FUNCTION_ARGS)
{
  BpChar *rc = PG_GETARG_BPCHAR_P(0);
  int l = VARSIZE (rc) - VARHDRSZ;
  while (*rc == ' ' || *rc == '0')
  {
    rc++;
    if (--l == 0) break;
  } 
  BpChar *res;
  res = palloc (VARHDRSZ + 1);
  VARATT_SIZEP (res) = VARHDRSZ + 1;
  strncpy(VARDATA(res), rc, l);
  PG_RETURN_BPCHAR_P (res);
}

> 
> thnx,
> Chris
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to