R
R
Ruslan Timurziev2017-12-04 11:13:32
PostgreSQL
Ruslan Timurziev, 2017-12-04 11:13:32

How to solve error in sql function which should export csv file?

Docker project.
There is a function:

\include_relative bbox_array.sql
\include_relative webapi_sheet_features_query.sql
\include_relative webapi_exec.sql

create or replace function webapi_sheet_features_excel__get
(req json, out head json, out body json)
language sql stable as $fn$
  copy (
    select webapi_exec(format(
      ... тут всякая логика ...
    ), req)
    from webapi_sheet_features_query(req)
  ) to './test.csv' with csv delimiter ','
$fn$; // !!!!ЗДЕСЬ 66 СТРОЧКА

To be able to use sql files, I run the make webapi command in the terminal, which stumbles over this function:
psql:/app/webapi_sheet_features_excel__get.sql:66: ERROR:  return type mismatch in function declared to return record
DETAIL:  Function's final statement must be SELECT or INSERT/UPDATE/DELETE RETURNING.
CONTEXT:  SQL function "webapi_sheet_features_excel__get"

Line 66 in the code is "$fn$;"
The task is combat, I will be glad if someone helps)
I practically don’t know SQL, except for all kinds of INSERT, UPDATE, DROP and others, when PeKhePahal with MySQL.
And how to upload a csv file to the user, with a GET request? The file should now be saved to the current directory './test.csv'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question