Re: Checking is TSearch2 query is valid

Lists: pgsql-general
From: Benjamin Arai <me(at)benjaminarai(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Checking is TSearch2 query is valid
Date: 2007-09-09 05:32:23
Message-ID: 01D6B981-B388-40AA-9088-D6361549569D@benjaminarai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Is there a way to pass a query to PostgreSQL to check if the
TSeasrch2 search text is valid? For example,

SELECT to_tsquery('default', '!');

returns an error. I want to know if there is a way get true/false
for the '!' portion of the query?

Benjamin


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Benjamin Arai <me(at)benjaminarai(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-09 05:45:54
Message-ID: Pine.LNX.4.64.0709090945140.2767@sn.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

There are two useful functions - numnode() and querytree()
More details in http://www.sai.msu.su/~megera/postgres/fts/doc/fts-query.html

Oleg
On Sat, 8 Sep 2007, Benjamin Arai wrote:

> Is there a way to pass a query to PostgreSQL to check if the TSeasrch2 search
> text is valid? For example,
>
> SELECT to_tsquery('default', '!');
>
> returns an error. I want to know if there is a way get true/false for the
> '!' portion of the query?
>
> Benjamin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83


From: Benjamin Arai <me(at)benjaminarai(dot)com>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-09 06:07:42
Message-ID: 721D7305-0B93-4530-8D2C-3405F5F855F4@benjaminarai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

That is helpful but these functions to do help me detect errors in
queries such as "(moose & frog" where the left parentheses is
missing. I may just have to write a lexical analyzer.

Benjamin

On Sep 8, 2007, at 10:45 PM, Oleg Bartunov wrote:

> There are two useful functions - numnode() and querytree()
> More details in http://www.sai.msu.su/~megera/postgres/fts/doc/fts-
> query.html
>
> Oleg
> On Sat, 8 Sep 2007, Benjamin Arai wrote:
>
>> Is there a way to pass a query to PostgreSQL to check if the
>> TSeasrch2 search text is valid? For example,
>>
>> SELECT to_tsquery('default', '!');
>>
>> returns an error. I want to know if there is a way get true/
>> false for the '!' portion of the query?
>>
>> Benjamin
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 1: if posting/reading through Usenet, please send an appropriate
>> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>> message can get through to the mailing list cleanly
>
> Regards,
> Oleg
> _____________________________________________________________
> Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
> Sternberg Astronomical Institute, Moscow University, Russia
> Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
> phone: +007(495)939-16-83, +007(495)939-23-83
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Benjamin Arai <me(at)benjaminarai(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-09 14:54:27
Message-ID: 18174.1189349667@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Benjamin Arai <me(at)benjaminarai(dot)com> writes:
> Is there a way to pass a query to PostgreSQL to check if the
> TSeasrch2 search text is valid? For example,
> SELECT to_tsquery('default', '!');
> returns an error. I want to know if there is a way get true/false
> for the '!' portion of the query?

The generic solution to this type of problem is to write a function that
tries to do whatever-it-is-that-throws-an-error inside a plpgsql
BEGIN/EXCEPTION block, and catch the errors you are expecting.

regards, tom lane


From: Benjamin Arai <me(at)benjaminarai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-10 05:23:26
Message-ID: 500554F8-D3FF-48D2-A461-3A748BA1EA0F@benjaminarai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Ok, this appears to have worked but I have to check for exception
code "OTHERS" because I could not figure out what the actual code
being thrown was. Is there a specific exception code for:

ERROR: no operand in tsearch query: "("

Thanks for the help!

Benjamin

On Sep 9, 2007, at 7:54 AM, Tom Lane wrote:

> Benjamin Arai <me(at)benjaminarai(dot)com> writes:
>> Is there a way to pass a query to PostgreSQL to check if the
>> TSeasrch2 search text is valid? For example,
>> SELECT to_tsquery('default', '!');
>> returns an error. I want to know if there is a way get true/false
>> for the '!' portion of the query?
>
> The generic solution to this type of problem is to write a function
> that
> tries to do whatever-it-is-that-throws-an-error inside a plpgsql
> BEGIN/EXCEPTION block, and catch the errors you are expecting.
>
> regards, tom lane
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Benjamin Arai <me(at)benjaminarai(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-10 13:39:46
Message-ID: 3403.1189431586@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Benjamin Arai <me(at)benjaminarai(dot)com> writes:
> Is there a specific exception code for:
> ERROR: no operand in tsearch query: "("

regression=# \set VERBOSITY verbose
regression=# select to_tsquery('(');
ERROR: 42601: no operand in tsearch query: "("
LOCATION: gettoken_query, tsquery.c:163

Seems to be "SYNTAX_ERROR".

regards, tom lane


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Benjamin Arai <me(at)benjaminarai(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2007-09-10 15:40:11
Message-ID: 20070910154011.GD5112@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Tom Lane wrote:
> Benjamin Arai <me(at)benjaminarai(dot)com> writes:
> > Is there a specific exception code for:
> > ERROR: no operand in tsearch query: "("
>
> regression=# \set VERBOSITY verbose
> regression=# select to_tsquery('(');
> ERROR: 42601: no operand in tsearch query: "("
> LOCATION: gettoken_query, tsquery.c:163
>
> Seems to be "SYNTAX_ERROR".

Hmm, maybe we should be displaying the textual name of the SQLSTATE
somehow.

--
Alvaro Herrera http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"El día que dejes de cambiar dejarás de vivir"


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Benjamin Arai <me(at)benjaminarai(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking is TSearch2 query is valid
Date: 2008-03-12 20:50:29
Message-ID: 200803122050.m2CKoTV23654@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


Add psql TODO:

o Include the symbolic SQLSTATE name in verbose error reports

http://archives.postgresql.org/pgsql-general/2007-09/msg00438.php

---------------------------------------------------------------------------

Alvaro Herrera wrote:
> Tom Lane wrote:
> > Benjamin Arai <me(at)benjaminarai(dot)com> writes:
> > > Is there a specific exception code for:
> > > ERROR: no operand in tsearch query: "("
> >
> > regression=# \set VERBOSITY verbose
> > regression=# select to_tsquery('(');
> > ERROR: 42601: no operand in tsearch query: "("
> > LOCATION: gettoken_query, tsquery.c:163
> >
> > Seems to be "SYNTAX_ERROR".
>
> Hmm, maybe we should be displaying the textual name of the SQLSTATE
> somehow.
>
> --
> Alvaro Herrera http://www.amazon.com/gp/registry/5ZYLFMCVHXC
> "El d?a que dejes de cambiar dejar?s de vivir"
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +