Skip navigation
1785 Views 6 Replies Latest reply: Feb 28, 2012 11:15 AM by nickg RSS
Priyaranjan Singh New Enzee 5 posts since
Feb 21, 2012
Currently Being Moderated

Feb 22, 2012 1:42 AM

embedded sql using c in netezza

Hello everybody,

 

In my project we are migrating data fron DB2 to netezza. we need to convert all the existing c scripts (using embedded SQL) to netezza. So, there is a requirement to write in c scripts using embedded SQL in netezza for extraction and processing of records from data warehouse. I want to know is it possible in netezza as done in DB2. If yes, then kindly guide me to steps to compile these c scripts in netezza server with examples or dummy codes.

 

Thanks and Regards,

Priyaranjan

  • nickg Active Enzee 248 posts since
    Mar 16, 2011
    Currently Being Moderated
    1. Feb 22, 2012 2:29 PM (in response to Priyaranjan Singh)
    Re: embedded sql using c in netezza

    You can run C code on an external CPU and execute SQL on Netezza via ODBC or JDBC.

     

    You can code UDF's in C# and other languages and compile and run them on Netezza using function calls embedded in SQL commands.  However, UDF's cannot execute SQL themselves.

     

    There are significant differences in how Netezza performs in certain situations.  Any reasonable migration needs to take this into account when moving from a traditional RDB environment.  It is usually ill advised to expect a simple porting of code to be an effective approach without first understanding how Netezza operates.

  • Bhuvaneswaran K New Enzee 43 posts since
    Nov 26, 2011
    Currently Being Moderated
    3. Feb 27, 2012 7:12 AM (in response to Priyaranjan Singh)
    Re: embedded sql using c in netezza

    You have the type "RECORD" in NZPLSQL and you can use looping to accomplish what you have done using cursors.

  • nickg Active Enzee 248 posts since
    Mar 16, 2011
    Currently Being Moderated
    4. Feb 27, 2012 6:06 PM (in response to Priyaranjan Singh)
    Re: embedded sql using c in netezza

    I did not say that.  SQL embedded in C needs to communicate with the database, usually using ODBC, which Netezza supports.  Your particular implementation of C probably has a library to handle the communications part and there is probably some configuration information somewhere so that the program knows what database to connect to.

     

    As to your other question, Netezza does not support cursors, but stored procedures do have a LOOP construct that allows you to iterate through a result set in much the same manner as a cursor.

     

    However, be warned!  Single row operations (UPDATE, INSERT, DELETE) in Netezza are VERY expensive.  Unless you are dealing with very few rows, such a process would perform very poorly (figure 5-6 operations per second for UPDATE or DELETE on a good day).  You should consider changing the process to perform updates using set operations to process large numbers of transactions in a single SQL statement.  Performance would increase by many orders of magnitude.  If all you are doing is SELECT, just send the query and deal with the result set in the C program.

     

    Also, it is possible (but not recommended) to run your own code on the Netezza host processor (it's just a LINUX machine after all).  But it offers no real advantage as it only cuts down communication overhead, and creates a whole bunch of disadvantages/issues (support, system stability, etc...).

     

    And you still need to go through ODBC to interact with the database, so the SQL still runs much the same as it would coming from an external machine.

  • nickg Active Enzee 248 posts since
    Mar 16, 2011
    Currently Being Moderated
    6. Feb 28, 2012 11:15 AM (in response to Priyaranjan Singh)
    Re: embedded sql using c in netezza

    I haven't written code is quite a while, so I cannot give you details on the API.  But, ODBC has been around for a long time and is an accepted standard as a database interface.  You can probably get API information off the web.

     

    You need to install the Netezza ODBC client on your machine (and the ODBC server portion on the Netezza box... your admin has probably already done that).  If you are working on Windows, its dead simple.  You then go into the standard ODBC app (on Windows) to configure the connection and give it a name.  From C you call the API routines using the name you gave to the connection.  If you have a UNIX client, it is a bit more work, but not that big of a deal.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

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