Re: isNumeric function?

From: Arguile <arguile(at)lucentstudios(dot)com>
To: Jerry LeVan <jerry(dot)levan(at)eku(dot)edu>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: isNumeric function?
Date: 2004-07-27 21:08:41
Message-ID: 1090962521.20911.13733.camel@broadswd.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2004-07-26 at 09:52, Jerry LeVan wrote:
> Is there a (relatively) simple way to tell if a column
> is a "numeric" type other than comparing against the
> seven or so oids which may or may not be the complete
> list of things genererally considered to be numeric?
>
> I need this info to determine whether or not to justify
> left or right in a data display.

No, in fact it's more complicated than your example. You'd also want to
consider which type a domain maps down to. There really isn't anything
you can do to know if an extended type is a simple numeric (without
running a regex on all the output data -- which is beyond icky). For
formatting you'd probably not want to consider composite types or arrays
as numeric even if they're totally composed of a builtin numeric base
type.

So, in addition to keeping a list of "pg_type.typname"s you consider
numeric, you'd also want UNION "pg_type.typbasetype" WHERE
"pg_type.typtype" = 'd' among some other restrictions.

See http://www.postgresql.org/docs/7.4/static/catalog-pg-type.html for
more info.

As you said this was in an application, your DB driver may automatically
map output types to SQL defined ones. If this is the case you might
consider just relying on your driver's mapping.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerry LeVan 2004-07-27 21:13:20 Aborting long running command.
Previous Message Arguile 2004-07-27 20:36:48 Re: Trigger on Postgres for tables syncronization