File: populate.ml

package info (click to toggle)
postgresql-ocaml 5.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 444 kB
  • sloc: ml: 2,783; ansic: 1,379; makefile: 28
file content (22 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(* Inverse operation of "dump" (using the sql command "copy ... from stdin") *)

open! Postgresql

let _ =
  if Array.length Sys.argv <> 3 then (
    Printf.printf
      "Usage:  populate conninfo table\n\
       Connect to PostgreSQL with [conninfo] (e.g. \"host=localhost\"),\n\
       and copy stdin to [table]\n";
    exit 1)

let main () =
  let c = new connection ~conninfo:Sys.argv.(1) () in
  let _ = c#exec ~expect:[ Copy_in ] ("copy " ^ Sys.argv.(2) ^ " from stdin") in
  c#copy_in_channel stdin;
  c#finish

let _ =
  try main () with
  | Error e -> prerr_endline (string_of_error e)
  | e -> prerr_endline (Printexc.to_string e)