Hello Monks,

I'm trying to find the best way to represent an SQL query using SQL::Abstract (actually SQL::Abstract::More via DBIx::DataModel; SQL::Abstract is also used by DBIx::Class). Unfortunately there is not a great deal of information on constructing SQL queries that fall outside the bounds of the usual 'SELECT * FROM x WHERE ...' using SQL::Abstract.

My ideal query:

SELECT CASE WHEN record.is_public = 'Yes' THEN 'public' WHEN EXISTS ( SELECT 1 FROM permissions WHERE permissions.rec_id = record.id AND user_id = $user_id ) THEN 'accessible' ELSE 'private' END AS viewable, record.id, record.display_name FROM record WHERE record.id = $rec_id; # or other criteria

...where $user_id and $rec_id (or other WHERE criteria) are supplied by the Perl code.

Has anyone used SQL::Abstract for this kind of query?

Thanks!


In reply to SQL::Abstract-ing subqueries by Anonymous Monk

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.