How to modify default Type (TSQuery) behaviour?

From: Łukasz Dejneka <l(dot)dejneka(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: How to modify default Type (TSQuery) behaviour?
Date: 2010-04-09 08:58:33
Message-ID: u2p4df5da451004090158k1a50200fn28a9a5fde01d13ac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all

I've asked related question on General list, but got no answer,
although I have been able to work around that issue a little bit.
There is one snag I encountered and I have no idea on how to work it
out.

I need to modify TSQuery object (add another operator and do some
stuff with it) - this is done and works properly at C code level. Now
I need to implement changes done in C on PG level. I really do not
want to make another type, tsquery2 or such...

What I've tried:
- the manual states that you can create your own data types with
CREATE TYPE command and alter some of their proprieties with ALTER
TYPE. But it is not possible to modify INPUT or OUTPUT function.
- I have created updated PG versions of the functions to_tsquery (the
CAST function) and tsqueryout (the TYPE OUTPUT) function and they are
in the "public" schema.
- I have created a CAST from text to tsquery pointing to
public.to_tsquery function.
- I have changed the search_path so the "public" schema is first.

How do I overwrite the default behaviour of Postgres 8.4, so I can
successfully run the following queries:

--1.
SELECT 'cat & dog & mouse'::tsquery; --uses the built in function
SELECT to_tsquery('cat & dog & mouse'); --also uses the built in function
--but
SELECT public.to_tsquery('cat & dog & mouse'); --uses new functions

--2.
SELECT CAST('dogs & cat' AS tsquery); --uses the built in function
--but
SELECT CAST('dogs & cat'::text AS tsquery); --uses new functions

--3.
SELECT public.to_tsquery('dog " mouse'); --new operator (doublequote),
works fine until OUTPUT function is called and as it is the default
one an error is displayed
--but
SELECT public.tsqueryout(CAST('dogs " cat'::text AS tsquery)); --uses
new functions and displays correctly

I thought that setting schema so "public" has priority over all other
would make PG use those functions in the first place. Also is the
string between the single quotes in SQL commands not treated as text
type? Is this why a CAST to ::text make it work in example 2?

Thanks in advance.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dhiraj Lohiya 2010-04-09 10:24:24 Re: Enhancing phonetic search support for more languages - GSoC 2010
Previous Message Fujii Masao 2010-04-09 08:18:35 Re: Remaining Streaming Replication Open Items