Loading CSV files

Loading OS NGD CSV files into databases

It is recommended that you have a basic understanding of database terminology before following the guides in the tabs below. The guides contain generic instructions, and it is recognised that there are multiple ways to load CSV files into databases which may be more suitable to your environment and existing processes.

Prior to loading the data into a database, it is necessary to create the relevant tables in the database. We have supplied the DDL statements that can be accessed in our OS NGD Resources GitHub repositoryarrow-up-right.

These instructions are based on PostgreSQLarrow-up-right version 14, but should work for all supported versions. The instructions assume that you have set-up your database with the PostGISarrow-up-right spatial extension.

Once connected to your PostgreSQL database, with the relevant schema and table created, the CSV file can be loaded with the following SQL statement using the COPY commandarrow-up-right:

COPY destination_schema.destination_table 
    FROM 'source_path_to_csv_file\source_name_of_csv_file.csv'
    DELIMITER ','
    CSV HEADER
    ENCODING 'UTF8';
circle-info

PostGIS will automatically store the geometry data that is supplied in Well-Known Text (WKT) format.

circle-exclamation

Last updated

Was this helpful?