Re: How to covert 'char' to 'inet' - Mailing list pgsql-general

From Darren Ferguson
Subject Re: How to covert 'char' to 'inet'
Date
Msg-id Pine.LNX.4.44.0207251017410.32008-100000@thread.crystalballinc.com
Whole thread Raw
In response to Re: How to covert 'char' to 'inet'  (Andrew Sullivan <andrew@libertyrms.info>)
Responses Re: How to covert 'char' to 'inet'  (Stephane Bortzmeyer <bortzmeyer@nic.fr>)
List 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


pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: How to covert 'char' to 'inet'
Next
From: Andrew Sullivan
Date:
Subject: Re: erserver