Thread: Using function like where clause

Using function like where clause

From
Ranieri Mazili
Date:
Hello,

I have 2 questions.
1) Can I use a function that will return a string in a where clause like
bellow?

select *
from table
where my_function_making_where()
          and another_field = 'another_think'

2) Can I use a function that will return a string to return the list of
columns that I want to show like below?

select my_function_making_list_of_columns()
from table
where field_test = 'mydatum'

Thanks

Re: Using function like where clause

From
Kev
Date:
On Aug 6, 3:44 pm, rmaz...@wgsystems.com.br (Ranieri Mazili) wrote:
> Hello,
>
> I have 2 questions.
> 1) Can I use a function that will return a string in a where clause like
> bellow?
>
> select *
> from table
> where my_function_making_where()
>           and another_field = 'another_think'
>
> 2) Can I use a function that will return a string to return the list of
> columns that I want to show like below?
>
> select my_function_making_list_of_columns()
> from table
> where field_test = 'mydatum'
>
> Thanks

Look up the quote_ident() function in the docs, you'll likely need
that for both cases.

Kev


Re: [SQL] Using function like where clause

From
hubert depesz lubaczewski
Date:
On Mon, Aug 06, 2007 at 04:44:29PM -0300, Ranieri Mazili wrote:
> 1) Can I use a function that will return a string in a where clause like
> bellow?
> 2) Can I use a function that will return a string to return the list of
> columns that I want to show like below?

not in sql. you can in pl/pgsql.

depesz

--
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA.  here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)