CSV to postgresql using stored procedure -


I want to copy the CSV to the database using the stored function. My work is as follows:

  Build function gis_portal.copycsv (in the path text) as' Zero 'with copy GIS_port al.temp_excel along the way DELIMITER' LANGUAGE Sql volatile LEAKPROOF;   

query

  from the path with CPI gis_portal.temp_excel DELIMITER ',' CSV header   

with .

While creating this function, giving error as a syntax error near the path.

Please help me.

  'copy GIS_portallet. Way via temp_excelDELIMITER' ^^^^^^^^ ^^   

What delimiter? If you use that keyword, then you have to specify one.

Try:

  create gis_portal.copycsv (in path path) $$ as zero return from $ cgi gis_portal.temp_excel with path DELIMITER ' , '$$ LANGUAGE sql;   

Or whatever you want.

In addition, you can not use the identifier in SQL Functions, you should use static parameters like $ 1. But because copy is not a static statement, you can not use the parameter in it. You must use PL / PGSQL and EXECUTE to run it as dynamic SQL:

  create gis_portal.copycsv (IN path text) Empty return EXECUTE format as $$ BEGIN ('copy GIS_portal. Temp_excel FROM% LDELIMITER'',' '', path); End; $$ LANGUAGE plpgsql;   

Note the double quotes around the delimiter as it is now a SQL string.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -