2

I want to bulk import data from a file present on my local into the Netezza Database using NZSQL language.

I tried with below query but, I am not able to do it.

create external table ext_tab (
login_email VARCHAR(10),identifier int,first_name VARCHAR(10),last_name VARCHAR(10)
)
USING (
DATAOBJECT('C:\Business\Imp Links\Netezza\Bulk Dir\email.csv') 
REMOTESOURCE 'jdbc'
DELIMITER ';'
SKIPROWS 1
MAXERRORS 1000
LOGDIR 'C:\Business\Imp Links\Netezza\Bulk Dir\Logs' );

create table email_details as select * from ext_tab;

This is my csv file named email.csv -

Login email;Identifier;First name;Last name
laura@example.com;2070;Laura;Grey
craig@example.com;4081;Craig;Johnson
mary@example.com;9346;Mary;Jenkins
jamie@example.com;5079;Jamie;Smith 

When I try to run this below command it gives error -

create table email_details as select * from ext_tab;

Error -

[Code: 1100, SQL State: HY000]  ERROR:  Transaction rolled back by client

I am not able to bulk import data into Netezza database hence, please guide me.

Tried with another below query, still throwing another error -

CREATE EXTERNAL TABLE my_external_table_new (
login_email VARCHAR(10),identifier int,first_name VARCHAR(10),last_name 
VARCHAR(10)
)
USING (DATAOBJECT ('C:\Business\Imp Links\Netezza\Bulk 
Dir\email_1.csv')
DELIMITER ','
REMOTESOURCE 'JDBC'
ESCAPECHAR '\' );
   
CREATE TABLE my_table_new (
login_email VARCHAR(10),identifier int,first_name VARCHAR(10),last_name 
VARCHAR(10)
)

insert into my_table_new (login_email, identifier, first_name, 
last_name)
select login_email, identifier, first_name, last_name
from my_external_table_new;

Error -

[Code: 1100, SQL State: HY000] ERROR: Remotesource option of external table was not defined to load/unload using a jdbc/dotnet client

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sujay777
  • 41
  • 5
  • Do you get the error immediately? Is it processing for sometime and then giving this error? Is there a firewall or network timeout enforced by a firewall? – Rajshekar Iyer Mar 16 '23 at 12:07
  • @Rajshekar Iyer while executing for first time it waited for 2 or 3 seconds, but next time onwards immediately throwing error. – sujay777 Mar 16 '23 at 12:32
  • Your updated error would indicate that you're trying to use jdbc client to load a table that is not defined with remotesource jdbc. I see you updated the final insert in your example from my_external_table to my_external_table_new...perhaps my_external_table was not a remotesource jdbc table. – Mike DeRoy Mar 16 '23 at 13:01

1 Answers1

1

In the log directory you should be able to find two files one with the extension .nzlog and the other with the extension .nzbad. the nzlog will tell you things like how many rows were loaded, how many were rejected, etc. the .nzbad file will contain all the records that failed to load. Your example fails to load because your first column 'login_email VARCHAR(10)' is not large enough to contain these email addresses. in my .nzlog file I see these errors

1: 2(10) [1, VARCHAR(10)] text field too long for column, "laura@exam"[p]
2: 3(10) [1, VARCHAR(10)] text field too long for column, "craig@exam"[p]
3: 4(10) [1, VARCHAR(10)] text field too long for column, "mary@examp"[l]
4: 5(10) [1, VARCHAR(10)] text field too long for column, "jamie@exam"[p]

you should retry with a larger size. if you hit more than the MAXERRORS argument you're setting that the transaction will roll back. for example, below you'll see that if I set maxerrors to 1 and try with this small amount of sample data the transaction will fail.

SYSTEM.ADMIN(ADMIN)=> create external table ext_tab2 ( login_email VARCHAR(10), identifier int, first_name VARCHAR(10), last_name VARCHAR(10)) using (dataobject('/tmp/exttbl') remotesource 'nzsql' delimiter ';' skiprows 1 maxerrors 1 logdir '/tmp');
CREATE EXTERNAL TABLE
SYSTEM.ADMIN(ADMIN)=> select * from ext_tab2;
ERROR:  External Table : count of bad input rows reached maxerrors limit
SYSTEM.ADMIN(ADMIN)=> create table example as select * from ext_tab2;
ERROR:  External Table : count of bad input rows reached maxerrors limit
SYSTEM.ADMIN(ADMIN)=> select * from example;
ERROR:  relation does not exist SYSTEM.ADMIN.EXAMPLE

If I increase the column size for email everything works

SYSTEM.ADMIN(ADMIN)=> create external table ext_tab3 ( login_email VARCHAR(50), identifier int, first_name VARCHAR(10), last_name VARCHAR(10)) using (dataobject('/tmp/exttbl') remotesource 'nzsql' delimiter ';' skiprows 1 maxerrors 1000 logdir '/tmp');
CREATE EXTERNAL TABLE
SYSTEM.ADMIN(ADMIN)=> create table example3 as select * from ext_tab3;
INSERT 0 4
SYSTEM.ADMIN(ADMIN)=> select * from example3;
    LOGIN_EMAIL    | IDENTIFIER | FIRST_NAME | LAST_NAME 
-------------------+------------+------------+-----------
 laura@example.com |       2070 | Laura      | Grey
 craig@example.com |       4081 | Craig      | Johnson
 mary@example.com  |       9346 | Mary       | Jenkins
 jamie@example.com |       5079 | Jamie      | Smith
(4 rows)
Mike DeRoy
  • 133
  • 7
  • 1
    one more note. the .badfile exists so you can manually review and fix any bad records and then load them later with another 'insert into table select from exttbl' command after the bulk load succeeds – Mike DeRoy Mar 16 '23 at 12:41
  • @Mark DeRoy I am still getting error as below [Code: 1100, SQL State: HY000] ERROR: Remotesource option of external table was not defined to load/unload using a jdbc/dotnet client – sujay777 Mar 16 '23 at 13:01
  • that indicates the external table you're selecting from was not defined as remotesource jdbc, but you're using a jdbc client. Create a new external table with remotesource jdbc defined. – Mike DeRoy Mar 16 '23 at 13:03
  • @Mark DeRoy Created new external table with remotesource jdbc , still giving error as below [Code: 1100, SQL State: HY000] ERROR: Transaction rolled back by client – sujay777 Mar 16 '23 at 13:18
  • but have you extended the login_email field? what does your .nzlog file show? – Mike DeRoy Mar 16 '23 at 13:22
  • @Mark DeRoy I have extended login_email field size to (varchar 50). .nzlog file showing no errors , only showing Load Options Fields – sujay777 Mar 16 '23 at 13:31
  • @Mark DeRoy Can you please try to import some another CSV or Text file which you have created and if it works, Please forward me that syntax and file both over here so I can create same in my DB. – sujay777 Mar 20 '23 at 04:57