Local CSV as criteria for SQL where clause against Network Netezza DB in Python
<p>In Python, I am querying against a Netezza database using SQL, and for one of the variables in the Netezza tables, I'd like to do an inner join from that to the same variable in an external CSV file. Is this possible? </p>

<p>Here is an example shell of my Python code, using pandas <code>read_sql</code> module</p>

<pre><code>*conn_nz = od.connect("DRIVER={NetezzaSQL};...")

q_test = ''' 
SELECT 
    A.var1,
    A.var2
FROM 
    Netezza.tableA A
WHERE 
   (A.var1 = csv.var1)

; '''
op_data = pd.read_sql(q_test, conn_nz)  
op_data*
</code></pre>

<p>Is this possible?  I'm very new to both SQL and Python.</p>

<p>Since it's a CSV, your best option is to create an <a href="http://www.ibm.com/support/knowledgecenter/SSULQD_7.2.1/com.ibm.nz.load.doc/c_load_external_tables.html" rel="nofollow">external table</a> in Netezza and join to that.</p>

<pre><code>create external table some_csv (
  column1 varchar(10)
  ,column2 varchar(20)
  ..
) using (
  dataobject '/path/to/file'
  delimiter ','
);
</code></pre>

<p>Then you can join to it directly from inside the database.</p>

<pre><code>select
  var1
  ,var2
from
  tableA
  join some_csv csv using (some_join_column)
</code></pre>

python csv netezza