Skip navigation
13426 Views 6 Replies Latest reply: Feb 10, 2012 7:40 AM by Saket Kale RSS
suman New Enzee 36 posts since
Apr 13, 2011
Currently Being Moderated

Jul 25, 2011 5:27 PM

To use NZ with perl

Hello there !

 

i'm tryin to find out what I need to invoke NZ SQL calls from a perl script..

 

I read in an old post by frankjustme, where he mentions that DBD::ODBC could be used, and has also put in a line require "/nz/kit/share/perl/nz/SQL.pm"; in his script. Is this something i need to install separately to be able to work with NZ in perl ?

  • Carlton Lo New Enzee 13 posts since
    Dec 16, 2010
    Currently Being Moderated
    1. Jul 7, 2011 4:41 PM (in response to suman)
    Re: To use NZ with perl

    I'm no expert, but you can take a look at the attached document.

    Essentially  you need Netezza ODBC driver, odbc.ini (configured) and DBD::ODBC perl mod.

  • Shawn Fox Enzee Exraordinaire 1,482 posts since
    Aug 15, 2006
    Currently Being Moderated
    2. Jul 11, 2011 11:33 AM (in response to suman)
    Re: To use NZ with perl

    If you are new to Perl, you may want to take a serious look at Python instead.  Perl is a very useful language, but the excessive use of symbols can make it very hard to read.  If you look at the overall usage of the two languages, I think you'll find that Python has been steadily displacing Perl over the last 5 or so years.

  • xgo Rookie 141 posts since
    Aug 28, 2010
    Currently Being Moderated
    4. Jul 29, 2011 12:35 PM (in response to Shawn Fox)
    Re: To use NZ with perl

    I use python to execute queryes with a very simple thin wrapper.

    Example:

     

    from pynz import *
    nz_conn = getDbConn('twinfin_ip', 'database_name', 'user', 'password')
    foreignkeys = query(nz_conn, """ SELECT     FK_NAME, FKTABLE_NAME, FKCOLUMN_NAME, PKTABLE_NAME, PKCOLUMN_NAME FROM     _V_ODBC_FOREIGNKEYS1""").fetchall()
    from pynz import *
    
    nz_conn = getDbConn('twinfin_ip', 'database_name', 'user', 'password')
    
    foreignkeys = query(nz_conn, """ SELECT     * FROM     _V_ODBC_FOREIGNKEYS1""").fetchall()
    

    Attachments:
  • frankjustme New Enzee 29 posts since
    Apr 12, 2010
    Currently Being Moderated
    5. Aug 4, 2011 1:44 PM (in response to Shawn Fox)
    Re: To use NZ with perl

    Suman,

     

    I copied from the perl scripts on the Netezza server....

     

    #!/usr/bin/perl
    use Getopt::Long;
    require "/nz/kit/share/perl/nz/SQL.pm";

     

    my $verbose;
    my $PROCID=$$;
    my $PROCNAME=$0;
    my $DBNAME=$ENV{NZ_DATABASE};

     

        $result = GetOptions ("verbose"  => \$verbose);  # flag

     

        if ( $verbose) {
            print " Usage: test.pl ";
            exit(0);
        }

     

        %myopt = ( KITDIR=> '/nz/kit' );
        nz::SQL::config(%myopt);
        my $sql;
        $sql = (" select 'somecol' as col1, 'col2' as col2 ");
        my $qresp = nz::SQL::query($DBNAME, $sql);
        my $errstr = nz::SQL::error();
        if ($errstr) {
            print "Sql Error $errstr sql =$sql\n";
            exit(99);
            }

     

        foreach my $row (@{$qresp->{data}}) {
            ($col1) = (@$row);
            print "New row Data: $col1\n";
            if ( $col1 =~ m/somecol/ ) {
                    print "do something here\n";
            }
        }
        exit(0);

     

    DBD::ODBC is an option but requires other components to install so go with the KISS method.

     

    Frank

  • Saket Kale New Enzee 17 posts since
    Jan 12, 2012
    Currently Being Moderated
    6. Feb 10, 2012 7:40 AM (in response to suman)
    Re: To use NZ with perl

    You need to give the path of the libnzodbc driver file in the odbc.ini file:

     

    Eg:

    odbc.ini
    [ODBC Data Sources]
    NZSQL = NetezzaSQL

     

    [NZSQL]

     

    Driver=/root/Desktop/libnzodbc.so

     

    Right now it is not able to find the driver file.

     

    Regards,

     

    Saket Kale.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points