By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

eval function?

P: n/a
-
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?
Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-
- 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.
Nov 23 '05 #2

P: n/a
Stu
- wrote:
- 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_literal(my_text) || ';';
EXECUTE my_query;
RETURN TRUE;
END;
$$ LANGUAGE plpgsql;
Stu

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.