Connecting Tech Pros Worldwide Help | Site Map

eval function?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 23rd, 2005, 02:03 AM
-
Guest
 
Posts: n/a
Default eval function?

i am using a regular expression in a select statement inside a function.
how do i dynamically insert a variable into the regexp?

eg. SELECT string ~ '\\d{X}'

where X is the dynamic variable.

I tried '\\d{' || X || '}'

obviously it didn't work.

is there an equivalent of javascript's eval() in postgresql?

  #2  
Old November 23rd, 2005, 02:03 AM
-
Guest
 
Posts: n/a
Default Re: eval function?

- wrote:[color=blue]
> i am using a regular expression in a select statement inside a function.
> how do i dynamically insert a variable into the regexp?
>
> eg. SELECT string ~ '\\d{X}'
>
> where X is the dynamic variable.
>
> I tried '\\d{' || X || '}'
>
> obviously it didn't work.
>
> is there an equivalent of javascript's eval() in postgresql?[/color]

somebody......... help me out please..

i want to put a variable into a WHERE clause e.g

WHERE
columnname ~ X

(X is a variable).

how should i do it?

columnnane ~ '' || X ||'' doesn't work.
  #3  
Old November 23rd, 2005, 02:03 AM
Stu
Guest
 
Posts: n/a
Default Re: eval function?

- wrote:
[color=blue]
> - wrote:[color=green]
>> i am using a regular expression in a select statement inside a function.
>> how do i dynamically insert a variable into the regexp?
>>
>> eg. SELECT string ~ '\\d{X}'
>>
>> where X is the dynamic variable.
>>
>> I tried '\\d{' || X || '}'
>>
>> obviously it didn't work.
>>
>> is there an equivalent of javascript's eval() in postgresql?[/color]
>
> somebody......... help me out please..
>
> i want to put a variable into a WHERE clause e.g
>
> WHERE
> columnname ~ X
>
> (X is a variable).
>
> how should i do it?
>
> columnnane ~ '' || X ||'' doesn't work.[/color]

I'm not sure what you are asking. If you are talking about PL/pgSQL, and
you don't want to do something with the result set, then you can just build
the query in a varchar and run it using EXECUTE. Something like this:

CREATE OR REPLACE FUNCTION some_function(text) RETURNS BOOLEAN AS $$
DECLARE
my_query VARCHAR(100);
my_text AS ALIAS FOR $1;
BEGIN
my_query := 'SELECT * FROM some_table WHERE some_column = '
|| quote_literal(my_text) || ';';
EXECUTE my_query;
RETURN TRUE;
END;
$$ LANGUAGE plpgsql;


Stu



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.