From: | Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz> |
---|---|
To: | Chris Boget <chris(at)wild(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Trunc in Postgres |
Date: | 2003-09-03 15:11:10 |
Message-ID: | Pine.LNX.4.44.0309031649250.22896-100000@kix.fsv.cvut.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-09-03 15:23:53 | Re: Localization (for dates) Oracle vs. Postgresql |
Previous Message | Adrian Phillips | 2003-09-03 15:05:19 | Re: Restarting, ownership, and permissions |