Thread

  1. Fails to add function from file with \i in psql

    PostgreSQL Bugs List <pgsql-bugs@postgresql.org> — 2000-11-26T20:28:24Z

    Roland Szabo (szroland@freemail.hu) reports a bug with a severity of 2
    The lower the number the more severe it is.
    
    Short Description
    Fails to add function from file with \i in psql
    
    Long Description
    For maintainance reasons, sql statements for our databases are saved in files, and upon installation, are executed via \i file.sql from psql. In postgres 7.3, we've encountered the following problem:
    
    In file trigger.sql, we create a trigger, and the function to be executed. (The list is in the example code part).
    We execute this with \i trigger.sql. No problems so far. Trying a simple insert statement though (from triggertest.sql):
    
    insert into pszlfej 
      (szsuf, szsth, szsui, szuuf, szuth, szuui)
    values 
      (1,1,1,1,1,1);
    
    yields to an error: 
    psql:triggertest.sql:4: NOTICE:  plpgsql: ERROR during compile of c_fnc 
    near line 1 
    "sql:triggertest.sql:4: ERROR:  parse error at or near "
    
    
    You say, there must be a syntax error in trigger.sql. But if we copy-paste the content of trigger.sql into psql, and execute it there (same as typing it), the function and trigger are created, and the insert statement also works.
    
    That means, the statements work just fine, and the error is most likely to be in psql.
    
    Sample Code
    trigger.sql:
    drop function c_fnc();
    create function c_fnc() returns opaque as '
    begin
       new.cdat := ''now'';
       new.cusr := getpgusername();
       return new;
    end;
    ' language 'plpgsql';
    
    
    drop trigger pszt_c_trig on pszltet;
    create trigger pszt_c_trig before insert
        on pszltet for each row execute procedure c_fnc();
    
    No file was uploaded with this report
    
    
    
  2. Re: Fails to add function from file with \i in psql

    Tom Lane <tgl@sss.pgh.pa.us> — 2000-11-27T01:06:59Z

    pgsql-bugs@postgresql.org writes:
    > psql:triggertest.sql:4: NOTICE:  plpgsql: ERROR during compile of c_fnc 
    > near line 1 
    > "sql:triggertest.sql:4: ERROR:  parse error at or near "
    
    Sounds like you saved your file with DOS-style newlines (\r\n).  The
    plpgsql parser doesn't think \r is whitespace.  That's changed for 7.1,
    but in the meantime use a less Microsofty editor...
    
    			regards, tom lane