title: Export BYTE/GRAPHIC Data from Teradata
body: <p>What is the best approach to export byte/graphic data from Teradata ? For a data migration project, can someone guide me on how to export data from teradata to snowflake. I am using TPT scripts and tdload approach, however, it doesn't seem to work.</p>
  <p>Approach that I have followed :</p>
  <ol>
  <li><p>Convert the data from byte to ASCII using FROM_BYTES() method in Teradata. However, during the ingestion process I was not able to get it bacl to original state.</p>
  </li>
  <li><p>Using FROM_BYTES() method with base10/base16 to get into the desired format, however, I am facing same issue with the process.</p>
  </li>
  </ol>
  <p>Below is Table structure :</p>
  <pre><code>CREATE SET TABLE DBC.AccessRights ,FALLBACK ,
       NO BEFORE JOURNAL,
       NO AFTER JOURNAL,
       CHECKSUM = DEFAULT,
       DEFAULT MERGEBLOCKRATIO,
       MAP = TD_DATADICTIONARYMAP
       (
        UserId BYTE(4) NOT NULL,
        DatabaseId BYTE(4) NOT NULL,
        TVMId BYTE(6) NOT NULL,
        FieldId SMALLINT FORMAT '---,--9' NOT NULL,
        AccessRight CHAR(2) CHARACTER SET LATIN UPPERCASE NOT CASESPECIFIC NOT NULL,
        WithGrant CHAR(1) CHARACTER SET LATIN UPPERCASE NOT CASESPECIFIC NOT NULL,
        GrantorID BYTE(4) NOT NULL,
        AllnessFlag CHAR(1) CHARACTER SET LATIN UPPERCASE NOT CASESPECIFIC NOT NULL,
        CreateUID BYTE(4),
        CreateTimeStamp TIMESTAMP(0),
        LastAccessTimeStamp TIMESTAMP(0),
        AccessCount INTEGER FORMAT '--,---,---,--9')
  PRIMARY INDEX ( UserId )
  PARTITION BY ( RANGE_N((ID2BIGINT(DatabaseId )) MOD  1073741824  BETWEEN 0  AND 1073741823  EACH 1 ),
  RANGE_N(ID2BIGINT(TVMId ) BETWEEN 0  AND 4294967295.  EACH 1 )ADD 2 );
  </code></pre>
  <p>Tpt Script :</p>
  <pre><code>USING CHARACTER SET UTF8
  DEFINE JOB EXPORT_DELIMITED_FILE
  DESCRIPTION 'Export rows from a Teradata table to a unformatted file'  (  DEFINE SCHEMA FILE_SCHEMA  (
  UserId BYTE(4),
  DatabaseId BYTE(4),
  TVMId BYTE(6),
  FieldId SMALLINT,
  AccessRight CHAR(4),
  WithGrant CHAR(2),
  GrantorID BYTE(4),
  AllnessFlag CHAR(2),
  CreateUID BYTE(4),
  CreateTimeStamp TIMESTAMP(0),
  LastAccessTimeStamp TIMESTAMP(0),
  AccessCount INTEGER
  );  
  
  DEFINE OPERATOR SQL_SELECTOR
  TYPE SELECTOR  SCHEMA FILE_SCHEMA ATTRIBUTES  
  (
    VARCHAR PrivateLogName = 'selector_log',  
    VARCHAR TdpId = &lt;host_id&gt;,
    VARCHAR UserName = &lt;user_name&gt;,
  
    VARCHAR UserPassword = &lt;password&gt;,,
    VARCHAR SelectStmt = 'SELECT * FROM DBC.AccessRights;',
    VARCHAR LobDirectoryPath = &lt;lob_dir&gt;
  );  
  
  DEFINE OPERATOR FILE_WRITER TYPE DATACONNECTOR CONSUMER SCHEMA *  ATTRIBUTES  
  (  
   VARCHAR PrivateLogName = 'dataconnector_log',
   VARCHAR DirectoryPath = &lt;dir_path&gt;,
   VARCHAR FileName = 'file.csv',
   VARCHAR FORMAT= 'BINARY',
   VARCHAR OpenMode = 'Write'
  );  
  
  APPLY TO OPERATOR (FILE_WRITER)
  SELECT * FROM OPERATOR (SQL_SELECTOR);  
  );
  </code></pre>