Re: Trunc in Postgres

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Trunc in Postgres
Дата
Msg-id Pine.LNX.4.44.0309031649250.22896-100000@kix.fsv.cvut.cz
обсуждение исходный текст
Ответ на Re: Trunc in Postgres  ("Chris Boget" <chris@wild.net>)
Список pgsql-general
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
>


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Localization (for dates) Oracle vs. Postgresql
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Trunc in Postgres