Re: How to covert 'char' to 'inet'

From: Darren Ferguson <darren(at)crystalballinc(dot)com>
To: Andrew Sullivan <andrew(at)libertyrms(dot)info>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to covert 'char' to 'inet'
Date: 2002-07-25 14:18:37
Message-ID: Pine.LNX.4.44.0207251017410.32008-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you are using IP addresses then Postgres has some really nice IP
related datatypes and functions such as INET

I would definately be inclined to use these instead of char() and
varchar().

Darren

On Thu, 25 Jul 2002, Andrew Sullivan wrote:

> On Wed, Jul 24, 2002 at 01:40:01AM -0700, Michal O wrote:
> > Thank you. What I did was:
> >
> > inet(trim(both ' ' from server_ip::text))
> >
> > and worked fine. Convertion to 'text' was needed.
> > Do you know how time consuming it is ? Is there more efficient way ?
>
> No, as I say, char() is padded, and spaces (or whatever) are not
> legal in IP addresses. So, if you have a char field with data
> 10.0.0.1, its actual representation is something more like
> '10.0.0.1_______', where '_' is the padding. This is the same
> problem you would have if you inserted the char() field into a
> newly-created varchar() field: you'd get the padded text instead.
> That's a reason to avoid using char() for most cases, unless you know
> that the field will _always_ be the same length.
>
> A
>
>

--
Darren Ferguson

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Maurice Walshe 2002-07-25 15:02:03 Re: Pl/pgSQL trigger failing and i ant see why
Previous Message Andrew Sullivan 2002-07-25 14:18:26 Re: How to covert 'char' to 'inet'