| --- |
| title: Examples - Read Fixed-Width Data |
| --- |
| |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| The following examples show how to read fixed-width data. |
| |
| ## Example 1 – Loading a table with PRESERVED\_BLANKS on |
| |
| ``` sql |
| CREATE READABLE EXTERNAL TABLE students ( |
| name varchar(20), address varchar(30), age int) |
| LOCATION ('gpfdist://host:port/file/path/') |
| FORMAT 'CUSTOM' (formatter=fixedwidth_in, name=20, address=30, age=4, |
| preserve_blanks='on',null='NULL'); |
| ``` |
| |
| ## Example 2 – Loading data with no line delimiter |
| |
| ``` sql |
| CREATE READABLE EXTERNAL TABLE students ( |
| name varchar(20), address varchar(30), age int) |
| LOCATION ('gpfdist://host:port/file/path/') |
| FORMAT 'CUSTOM' (formatter=fixedwidth_in, name='20', address='30', age='4', |
| line_delim='?@'); |
| ``` |
| |
| ## Example 3 – Create a writable external table with a \\r\\n line delimiter |
| |
| ``` sql |
| CREATE WRITABLE EXTERNAL TABLE students_out ( |
| name varchar(20), address varchar(30), age int) |
| LOCATION ('gpfdist://host:port/file/path/filename') |
| FORMAT 'CUSTOM' (formatter=fixedwidth_out, |
| name=20, address=30, age=4, line_delim=E'\r\n'); |
| ``` |
| |
| |