What datatype should I use to store an IP Address?

Started by Andre Lopesabout 16 years ago3 messagesgeneral
Jump to latest
#1Andre Lopes
lopes80andre@gmail.com

Hi,

I'm using Varchar(16) to store an IP Address. PostgreSQL offers another
datatypes to store IP's or it is OK to store in Varchar(16)?

Best Regards,

#2Michał Pawlikowski
misiekbest@gmail.com
In reply to: Andre Lopes (#1)
Re: What datatype should I use to store an IP Address?

On Thu, Mar 25, 2010 at 11:25 AM, Andre Lopes <lopes80andre@gmail.com> wrote:
Hi,

I'm using Varchar(16) to store an IP Address. PostgreSQL offers another
datatypes to store IP's or it is OK to store in Varchar(16)?

Best Regards,

Yes, just look here:
http://www.postgresql.org/docs/8.4/static/datatype-net-types.html

#3Devrim GÜNDÜZ
devrim@gunduz.org
In reply to: Michał Pawlikowski (#2)
Re: What datatype should I use to store an IP Address?

On Thu, 2010-03-25 at 11:28 +0100, Michał Pawlikowski wrote:

I'm using Varchar(16) to store an IP Address. PostgreSQL offers
another datatypes to store IP's or it is OK to store in Varchar(16)?

Yes, just look here:
http://www.postgresql.org/docs/8.4/static/datatype-net-types.html

Alternatively, you can use ip4r:

http://pgfoundry.org/projects/ip4r

"ip4 and ip4r are types that contain a single IPv4 address and a range
of IPv4 addresses respectively. They can be used as a more flexible,
indexable version of the cidr type."

Regards,
--
Devrim GÜNDÜZ
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
PostgreSQL RPM Repository: http://yum.pgrpms.org
Community: devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org Twitter: http://twitter.com/devrimgunduz