Note that there are some explanatory texts on larger screens.

plurals
  1. POImport csv file into psql db
    primarykey
    data
    text
    <p>I want to import csv file to psql db...</p> <p>I have searched and tried using copy, also referred <a href="https://www.commandprompt.com/ppbook/r23528" rel="nofollow">https://www.commandprompt.com/ppbook/r23528</a> and the syntax i used is:</p> <pre><code>copy location from 'file.csv' with delimiters '\t' NULL as 'NULL' CSV; </code></pre> <p>Note : My csv file is delimited by 'tab' . </p> <p>After executing the above cmd 1st time, it shows : </p> <pre><code>ERROR: syntax error at or near ""\t"" LINE 1: ...om 'file.csv' using delimiters "\t" ; </code></pre> <p>and for 2nd time,</p> <pre><code>ERROR: syntax error at or near "copy" LINE 2: copy location from 'file.csv' using d... </code></pre> <p><strong>After Editing,</strong> </p> <p>2nd time i tried to use like ,</p> <pre><code>copy location from 'file.csv' with delimiter E'\t' NULL as 'NULL' CSV; ERROR: extra data after last expected column CONTEXT: COPY location, line 1: "AD AD100 Canillo 42.5833 1.6667 6" </code></pre> <p>My table description is </p> <pre><code>Table "public.location" Column | Type | Modifiers -------------+------------------------+----------- countrycode | character varying(2) | postalcode | character varying(20) | place | character varying(100) | state | character varying(20) | country | character varying(100) | country2 | character varying(20) | community | character varying(100) | community2 | character varying(20) | latitude | double precision | longitude | double precision | accuracy | integer | </code></pre> <p>how to solve this? </p> <p><strong>Input:</strong></p> <pre><code>AD AD100 Canillo 42.5833 1.6667 6 AD AD200 Encamp 42.5333 1.6333 6 AD AD300 Ordino 42.6 1.55 6 AD AD400 La Massana 42.5667 1.4833 6 AD AD500 Andorra la Vella 42.5 1.5 6 AD AD600 Sant Julià de Lòria 42.4667 1.5 6 AD AD700 Escaldes-Engordany 42.5 1.5667 6 AR 3636 "POZO CERCADO (EL CHORRO (F), DPTO. RIVADAVIA (S))" SALTA A -23.4933 -61.9267 3 AR 4123 LAS SALADAS SALTA A -25.7833 -64.5 4 AR 4126 LA MARAVILLA SALTA A -26.0833 -65.263 3 AR 4126 TALA SALTA A -26.1167 -65.2833 4 AR 4126 LA ASUNCION SALTA A -26.0833 -65.263 3 AR 4126 BRETE SALTA A -26.0667 -65.3667 4 AR 4126 EL SUNCHAL SALTA A -26.0833 -65.263 3 AR 4126 CEIBAL SALTA A -26.1 -65.0167 4 AR 4126 BARADERO SALTA A -26.0833 -65.263 3 AR 4126 CANDELARIA SALTA A -26.1 -65.1 4 AR 4126 ALEM SALTA A -26.0833 -65.263 3 AR 4126 EL BRETE SALTA A -26.0667 -65.3667 4 AR 4126 EL CUIBAL SALTA A -26.0833 -65.263 3 AR 4126 EL JARDIN SALTA A -26.0833 -65.3833 4 AR 4126 OVEJERO SALTA A -26.0833 -65.263 3 AR 4126 LOS MOGOTES SALTA A -26.0333 -65.2 4 AR 4126 "MIRAFLORES (TALA, DPTO. CANDELARIA)" SALTA A -26.0833 -65.263 3 </code></pre> <p>This is some eg for input...</p> <p>when i open this file in ms xcel sheet, with delimiter tab , it seperates the data correctly to the relevent coloumn.. </p> <p><strong>input files with tab and null values,</strong></p> <pre><code>AD\tAD100\tCanillo\t\n\t\n\t\n\t\n\t\n\t\n\t42.5833\t1.6667\t6 AD\tAD200\tEncamp\t\n\t\n\t\n\t\n\t\n\t\n\t42.5333\t1.6333\t6 AR\t3636\t"POZO CERCADO (EL CHORRO (F), DPTO. RIVADAVIA (S))"\tSALTA\tA\t\n\t\n\t\n\t\n\t-23.4933\t-61.9267\t3 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload