Hi monks,

I am currently trying to use Perl and Postgresql together.
I would like to insert a regex containing a variable into the SQL statement but am unsure of how to do this.
$sth_get_branch_list = $dbh->prepare(q( SELECT branch FROM postgres_database WHERE tree = 'first_tree' AND branch ~ /$root\.\d+/; ));

The basic aim of the script will be find sub branches of a root.
e.g. $root = stick, and what I want to find is all branches attached to $root, e.g. stick.1, stick.2, stick.300 etc...

I basically can't get the regex to work at all, I don't think it seems to work like normal Perl regexes, but I am not sure. I have tried a whole multitude of syntaxes.

All help greatly appreciated!
Cheers
Chris

In reply to Perl and PostgreSQL regex by chrishowe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.