dbTalk Databases Forums  

eval function?

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss eval function? in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
-
 
Posts: n/a

Default eval function? - 02-17-2005 , 10:58 PM






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?

Reply With Quote
  #2  
Old   
-
 
Posts: n/a

Default Re: eval function? - 02-18-2005 , 11:58 PM






- wrote:
Quote:
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?
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.


Reply With Quote
  #3  
Old   
Stu
 
Posts: n/a

Default Re: eval function? - 02-19-2005 , 04:45 AM



- wrote:

Quote:
- wrote:
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?

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.
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:
| quote_literal(my_text) || ';';
EXECUTE my_query;
RETURN TRUE;
END;
$$ LANGUAGE plpgsql;


Stu





Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.