Querying PostgreSQL, timtowtdi:

-- versions 7.4 thru 9: # select substring(version() from E'^PostgreSQL (\\S+)') ; substring ----------- 8.4.4 (1 row) -- versions 7.4 thru 9: # select current_setting('server_version'); current_setting ----------------- 8.4.4 (1 row) -- versions 8.2 thru 9: # select current_setting('server_version_num'); current_setting ----------------- 80404 (1 row)

DBIx-Version looks unmaintained, but maybe it has some useful examples.

(update) There is info in DBD::Pg attributes as well:

perl -MDBI -e'my$dbh=DBI->connect("dbi:Pg:"); print $dbh->{pg_server_v +ersion}, "\n"'; 80404

Then, the 2008 SQL standard prescribes a SQL_IMPLEMENTATION_INFO view which (in postgres) has this information:

select implementation_info_name, character_value from information_schema.sql_implementation_info where implementation_info_name ~ 'DBMS'; implementation_info_name | character_value --------------------------+----------------- DBMS NAME | PostgreSQL DBMS VERSION | 08.04.0004 (2 rows)

I seem to remember that, alas, this latter solution (although standard and therefore in principle the 'best') is not very widely available.


In reply to Re: Finding database version from handle? by erix
in thread Finding database version from handle? by cosmicperl

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.