From: tjk@tksoft.com <tjk@tksoft.com>
To: khj@cs.appstate.edu
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Expr Abbreviations/Functions?
Date: Sat, 24 Jul 1999 16:11:57 -0700 (PDT)
Message-ID: <199907242311.QAA27601@uno.tksoft.com> (raw)
In-Reply-To: <e3dye2i9c.fsf@beagle.cs.appstate.edu>
Kenneth,
You could merge the fields and search with :
select * from tablex where lower(f1||f2||f3) ~ 'foo';
Troy
Troy Korjuslommi Tksoft OY, Inc.
tjk@tksoft.com Software Development
Open Source Solutions
Hosting Services
>
> I find myself frequently typing (postgresql-6.5.1) the following:
>
> SELECT * FROM table
> WHERE (f1 ~* 'foo' OR f2 ~* 'foo' OR f3 ~* 'foo');
>
> Can "CREATE FUNCTION" be used? Something like
>
> CREATE FUNCTION f(string)
> RETURNS bool
> AS '(f1 ~* '$1' OR f2 ~* '$1' ...)';
>
> and then type
>
> SELECT * FROM table WHERE f('foo');
>
>
> I tried to define such a function, but encountered two problems:
>
> o It didn't "accept" the function's definition
>
> o Syntax errors (apostrophes need escaping ... I tried mixing quotes
> and apostrophes, also using '\' chars ... nothing seemed to work)
>
>
> I know that I can define VIEWs (and FUNCTIONs) that contain a specific
> SELECT statement, but I'd prefer to have definitions of just the
> repeating expressions.
>
>
> Another thing I'd like to "abbreviate" is the second phrase in
> SELECTs. E.g,
>
> SELECT x FROM table;
>
> instead of
>
> SELECT x1,x2,x3 FROM table;
>
> where 'x' is somehow equivalent to 'x1,x2,x3'.
>
>
> I read the online docs and searched a few SQL books, but can't seem to
> find the correct approach. Ideas?
>
> Thanks for any help,
>
> -Prof Kenneth H Jacker khj@cs.appstate.edu
> -Computer Science Dept www.cs.appstate.edu/~khj
> -Appalachian State Univ
> -Boone, NC 28608 USA
>
>
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tjk@tksoft.com, khj@cs.appstate.edu
Subject: Re: [SQL] Expr Abbreviations/Functions?
In-Reply-To: <199907242311.QAA27601@uno.tksoft.com>
References: <e3dye2i9c.fsf@beagle.cs.appstate.edu> <199907242311.QAA27601@uno.tksoft.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox