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
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.
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>…
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:
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.
In version 7.2 of Netezza you can now specify the IncludeHeader option to achieve this with external tables.
This is documented here
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With