This directory contains the code for the user-defined functions,
text_cidr() and text_inet(), than can cast text fields into the
Postgres network types.



SYNOPSIS
========

SELECT text_inet(text_field);
SELECT ... FROM ... WHERE text_cidr(text_field) >> '192.168.200.1';


DESCRIPTION
===========

The two functions can cast text field into network types. These casts
are missing in Postgres -> 7.1.2
They are implemented as external functions, so the regular cast notation
cannot be used.
When a text field containing a non IP adress is converted, the result is
simply the '0.0.0.0/32' IP adresse, instead of an error or a NULL (if
someone can provide a patch to return NULL upon parse error, you're
welcome).


FILES
=====

Makefile                building instructions for the shared library
README                  the file you are now reading
network-install.sql.in  SQL code needed to register these functions
network-remove.sql      SQL code required to undo the installation
network.c               the c code for the functions
pg-network.txt          the original patch from Alex Pilosov against Postgres 7.1.2


INSTALLATION
============

To install the function, run

	make
	make install

For this to work, make sure that:

. the source directory is in the postgres contrib directory, or
. the PGDIR variable in the Makefile is updated
. the user running "make install" has postgres administrative authority
. this user's environment defines the PGLIB and PGDATA variables and has
  postgres binaries in the PATH.

This way, the function will be installed in the template1
database. All subsequently created databases will inherit it.
The databases created prior to such installation will need to be
destroyed and re-created in order to inherit the function. If that's
not desired, the function can be added to each individual database
with:

	psql -d <database_name> < network-install.sql

To remove a previously installed version of the type from template1,
run
	make remove

To remove from individual databases, run

	psql -d <database_name> < network-remove.sql


EXAMPLE
=======

nhuillard=> CREATE TABLE foo (bar text);
CREATE
nhuillard=> INSERT INTO foo (bar) VALUES ('nhuillard');
INSERT 55513737 1
nhuillard=> INSERT INTO foo (bar) VALUES ('192.168.200.1/24');
INSERT 55513738 1
nhuillard=> INSERT INTO foo (bar) VALUES ('300.300.300.1/24');
INSERT 55513739 1
nhuillard=> SELECT bar, text_cidr(bar), text_cidr(bar) >> '192.168.200.2'::inet FROM foo;
bar             |text_cidr     |?column?
----------------+--------------+--------
nhuillard       |0.0.0.0/32    |f       
192.168.200.1/24|192.168.200/24|t       
300.300.300.1/24|0.0.0.0/32    |f       
(3 rows)


-----------------------------------------------------------------------------
Nicolas huillard
nhuillard@ghs.fr
