in reply to Perl and PostgreSQL regex

chrishowe:

Try changing your expression to:

$sth_get_branch_list = $dbh->prepare(q( SELECT branch FROM postgres_database WHERE tree = 'first_tree' AND branch ~ '$root\.\d+'; ));

(You don't use slashes for regular expressions in PostgreSQL, see http://www.postgresql.org/docs/8.3/static/functions-matching.html and http://www.oreillynet.com/pub/a/databases/2006/02/02/postgresq_regexes.html.)

Update: Since I don't use PostgreSQL, there are probably other differences as well.

Update 2: In this case, you really don't need regular expressions anyway, you could use:

$sth_get_branch_list = $dbh->prepare(q( SELECT branch FROM postgres_database WHERE tree = 'first_tree' AND branch like '$root%'; ));
...roboticus

Replies are listed 'Best First'.
Re^2: Perl and PostgreSQL regex
by chrishowe (Acolyte) on Mar 03, 2009 at 13:49 UTC
    See now I have tried your first solution but all I get is the following error:
    WARNING: nonstandard use of escape in a string literal LINE 3: AND branch ~ '$root\.\d... ^ HINT: Use the escape string syntax for escapes, e.g., E'\r\n'..
    Which is confusing me a little :-)