Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create external table with headers in netezza (postgres)

Tags:

csv

netezza

I am creating an external table as shown below

CREATE EXTERNAL TABLE '~\test.csv' 
USING ( DELIMITER ',' Y2BASE 2000 ENCODING 'internal' REMOTESOURCE 'ODBC' ESCAPECHAR '\' )
AS SELECT * FROM TEST_TABLE;

It works fine. My question is :

Is there a way we can name the header values as column names in the test.csv file ? Is it possible in either Netezza or postgres.

I think we can do it using COPY, however I want to do it using the EXTERNAL TABLE command.

Thanks

like image 763
Nikhil Das Nomula Avatar asked Apr 30 '13 16:04

Nikhil Das Nomula


People also ask

How do I create an external table in Netezza?

You can use the CREATE EXTERNAL TABLE command to create external tables. An external table allows IBM® Netezza® to treat an external file as a database table. To create an external table, you must have the CREATE EXTERNAL TABLE administration privilege and the List privilege on the database where you are defining the table.

How to distribute data in Netezza on first column?

By default, Netezza distributes on first column if you do not specify DISTRIBUTE ON clause: In above table, Netezza distribute data on col1. You can create the table from the other existing table, temporary table or external table by using CREATE TABLE AS command: CREATE TABLE <tablename> [ ( <col> [,<col>…

Is there a way to include header in Netezza query?

In version 7.2 of Netezza you can now specify the IncludeHeader option to achieve this with external tables. Show activity on this post. It's not pretty, and it would likely add some amount of overhead to the query, but you could do something like this:

How can I access files stored on the Netezza performance server server?

You can use external tables to access files that are stored on the Netezza Performance Serverhost server. Additionally, Netezza Performance Servercan treat a file on a client system as a remote external table by using the REMOTESOURCEoption.


2 Answers

In version 7.2 of Netezza you can now specify the IncludeHeader option to achieve this with external tables.

This is documented here

like image 113
ScottMcG Avatar answered Oct 03 '22 13:10

ScottMcG


It's not pretty, and it would likely add some amount of overhead to the query, but you could do something like this:

CREATE EXTERNAL TABLE ... AS
SELECT ColumnId, OtherColumn 
FROM (
    SELECT FALSE as IsHeader, ColumnId::VARCHAR(512), OtherColumn::VARCHAR(512)
    FROM TEST_TABLE
    UNION ALL
    SELECT TRUE as IsHeader, 'ColumnId', 'OtherColumn'
) x
ORDER BY IsHeader DESC
like image 33
qSlug Avatar answered Oct 03 '22 15:10

qSlug