csvconstantspgloader

Pgloader -- How to load constant while using load csv


I am using pgloader to load file into Tables. I need to load constant (ie, field not provided by the csv) but I do not succeed.

my configuration looks like :

LOAD CSV  
  FROM './file.csv'
  HAVING FIELDS
  (a, b, c)
INTO postgresql:///pgloader?my_table
  TARGET COLUMNS
  (
    a
    ,b   
    ,c  
    ,Src
  )
  WITH
    skip header = 0,  
    fields optionally enclosed by '"',  
    fields escaped by double-quote,  
    fields terminated by ';'  
;

and I need to put 'SRC' static value into the field my_table.Src.

Do you have any idea?

Thanks.

regards,

-- Julien


Solution

  • Just use the 'using' instruction

    LOAD CSV  
      FROM './file.csv'
      HAVING FIELDS
      (a, b, c)
    INTO postgresql:///pgloader?my_table
      TARGET COLUMNS
      (
        a,
        b,   
        c,  
        Src text using "SRC"
      )
      WITH
        skip header = 0,  
        fields optionally enclosed by '"',  
        fields escaped by double-quote,  
        fields terminated by ';'  
    ;