dimitri / pgloader

Migrate to PostgreSQL in a single command!
http://pgloader.io
Other
5.45k stars 548 forks source link

Anonymous code blocks don't work #1585

Open ffried opened 5 months ago

ffried commented 5 months ago
LOAD CSV
     FROM INLINE with encoding 'ascii'
     INTO postgresql:///pgloader
     TARGET TABLE jordane

     WITH truncate,
          fields terminated by '|',
          fields not enclosed,
          fields escaped by backslash-quote

      SET work_mem to '128MB',
          standard_conforming_strings to 'on'

   BEFORE LOAD DO
    $$ drop table if exists jordane; $$,
    $$ CREATE TABLE jordane
       (
         "NOM" character(20),
         "PRENOM" character(20)
       )
    $$
    AFTER LOAD EXECUTE 'my_script.sql';

BORDET|Jordane
BORDET|Audrey
LASTNAME|"opening quote
BONNIER|testprenombe~aucouptroplong
JOURDAIN|héhé¶

Contents of my_script.sql:

DO $$
BEGIN
EXECUTE 'select 1;';
END;
$$;
2024-05-29T10:58:36.049000Z LOG pgloader version "3.6.7~devel"
2024-05-29T10:58:36.054000Z LOG Parsing commands from file #P"/work/DBMigrate.load"
KABOOM!
END-OF-FILE: end of file on #<dynamic-extent STRING-INPUT-STREAM (unavailable) from "DO $$
BE...">
An unhandled error condition has been signalled:
   end of file on #<dynamic-extent STRING-INPUT-STREAM (unavailable) from "DO $$
BE...">

What I am doing here?

end of file on #<dynamic-extent STRING-INPUT-STREAM (unavailable) from "DO $$
BE...">
ffried commented 5 months ago

I just noticed, that the DO block isn't the problem. It seems the EXECUTE is the actual trigger here. I'm not sure what exactly the underlying issue is, but #945 fixes it!