URI PostgreSQL Base Type
------------------------------------------------

The version of liburi supplied has been modified to join path and params.

Modify the Makefile and adjust the include paths to match your postgresql installation.

Then simply run:

make && make install

If you wish for this type to be present in all newly created databases,
install this type in template1.

Otherwise, choose the database you wish to install the type in, and substitute
<dbname> in the following:

psql <dbname> < /path/to/uri/uri.sql

the uri type is now ready for use.

Usage:
------------------------------------------------

The uri type acts in most cases like the text type, the difference being,
that all input is validated according to RFC 2396.

Also supplied is a composite type, uri_table, which allows you simple access
to an uri's component parts. This type should NOT be used in a create table 
statement, as no usable functions are provided to return the uri_table data
to uri format.

Example:

CREATE TABLE urls (url uri);
INSERT INTO urls (url) VALUES ('http://pgfoundry.org/projects/uri');

SELECT (url::uri_table).host FROM urls;

     host
---------------
 pgfoundry.org
(1 row)

any type of uri can be stored, not just urls:
DELETE FROM urls;
INSERT INTO urls (url) VALUES ('mailto:john@geeknet.com.au');

SELECT (url::uri_table).username,(url::uri_table).host FROM urls;

 username |      host
----------+----------------
 john     | geeknet.com.au
(1 row)

uri's a processed in their canonical form, but stored in their unescaped form.
This means that where the text type would render two string not equal, the uri
type correctly identifies them as equal:

DELETE FROM urls;
INSERT INTO urls (url) VALUES ('http://pgfoundry.org/projects/uri');
SELECT * FROM urls WHERE url = 'http://PGfoundry.org/projects/uri';

                url
-----------------------------------
 http://pgfoundry.org/projects/uri
(1 row)

SELECT * FROM urls WHERE url = 'http://PGfoundry.org/projects/%75%72%69';

                url
-----------------------------------
 http://pgfoundry.org/projects/uri
(1 row)

and even 
SELECT * FROM urls WHERE url = 'http://%70%67%66%6F%75%6E%64%72%79%2E%6F%72%67/projects/%75%72%69';

                url
-----------------------------------
 http://pgfoundry.org/projects/uri
(1 row)

At present, only the btree and hash operator classes are implemented, but plans
are in place to implement gist support.

However, one of the most common use cases are indexing just the host part.
This can be achieved by:

CREATE INDEX urls_idx ON urls (((url::uri_table).host));

explain SELECT * FROM urls WHERE (url::uri_table).host = 'pgfoundry.org';

			      QUERY PLAN
----------------------------------------------------------------------
 Index Scan using urls_idx on urls  (cost=0.00..4.68 rows=1 width=32)
   Index Cond: (((url)::uri_table).host = 'pgfoundry.org'::text)
(2 rows)

Another useful feature is converting relative uri's to absolute uri's by
supplying a base uri. The @ operator is supplied for this purpose:

SELECT '../bar.htm'::uri @ 'http://www.foo.com/foo/'::uri;

          ?column?
----------------------------
 http://www.foo.com/bar.htm
(1 row)

For a detailed function list, see uri.sql, it's mostly self-explaining.
