1

I write the function, but it occurs error " ERROR: syntax error at or near "\""

I want to create file, But it does not seem to work.

How do I do it ?

CREATE OR REPLACE FUNCTION sqlDB (fileName VARCHAR)
RETURNS void AS $$
DECLARE
BEGIN
  \i /tmp/fileName;
END;
$$ language plpgsql;
Jim Jones
  • 18,404
  • 3
  • 35
  • 44
ko_ma
  • 911
  • 2
  • 11
  • 26
  • 1
    `\i` is a command specific to the `psql` it is not a [SQL command](https://www.postgresql.org/docs/current/static/sql-commands.html) so you can not use it in a PL/pgSQL or SQL function –  Jul 18 '18 at 08:53
  • @a_horse_with_no_name Is there no other way to create sql files in function? – ko_ma Jul 18 '18 at 09:02
  • 1
    I know its not on the tags but you can easily do that using a shell script. – kimdasuncion12 Jul 18 '18 at 10:06
  • plpythonu f.open(), f.write(), f.close() Ref https://stackoverflow.com/questions/39812722/how-can-i-write-to-a-file-on-disk-from-pl-pgsql –  Jul 06 '19 at 18:25

0 Answers0