Feb 22, 2012 1:42 AM
embedded sql using c in netezza
-
Like (0)
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
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.
hi Nick,
Thanks for ur worthy reply. From your reply i can say that writting c scripts embedded with sql querries is not possible. Rather i can write UDF's and call it in sql query. The functionality of previous DB2 c script can be changed into stored procedure. Also tell me if records and cursors can be used in procedure in netezza as used in PL/SQL.
You have the type "RECORD" in NZPLSQL and you can use looping to accomplish what you have done using cursors.
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.
Hi Nick,
Once again thanks to you. since I am new to this ODBC and Netezza. so, kindly tell me how to compile a piece of c code (containing embedded sql) in Unix. Also, How to install ODBC driver in Netezza and from where I can get it. If you have any document related to above, then please share it. It will be of great help for me.
Regards,
Priyaranjan
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.

