Skip to main content
additional explanations
Source Link
mimic
  • 5.3k
  • 7
  • 63
  • 106

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I solved this problem added parentheses

('"' || account_object.valid_status || '"')

But it looks awful and can't believe there is no normal way to solve? Another problem with Null - it just isn't included in the tuple: (,0) - how is supposed to handle it?

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I solved this problem added parentheses

('"' || account_object.valid_status || '"')

But it looks awful and can't believe there is no normal way to solve?

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I solved this problem added parentheses

('"' || account_object.valid_status || '"')

But it looks awful and can't believe there is no normal way to solve? Another problem with Null - it just isn't included in the tuple: (,0) - how is supposed to handle it?

update
Source Link
mimic
  • 5.3k
  • 7
  • 63
  • 106

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I solved this problem added parentheses

('"' || account_object.valid_status || '"')

But it looks awful and can't believe there is no normal way to solve?

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I solved this problem added parentheses

('"' || account_object.valid_status || '"')

But it looks awful and can't believe there is no normal way to solve?

fix error
Source Link
mimic
  • 5.3k
  • 7
  • 63
  • 106

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly?

I'm calling a Postgres function from Flask-SQLAlchemy. The function returns a table with 2 values: string and number:

CREATE OR REPLACE FUNCTION public.test (
  id varchar
)
RETURNS TABLE (
  project_name varchar,
  projects_num integer
) AS
$body$
DECLARE 
BEGIN    
...
RETURN QUERY (SELECT project.name as project_name, project_nums as projects_num);   
END;
$body$
LANGUAGE 'plpgsql'

On the Flask side I'm doing the following call:

engine = create_engine(url)
connection = engine.connect()
result = connection.execute('SELECT "test"(\'123\')').fetchone()

Then I'm trying to get data from result.

for row in result:
    print(literal_eval(row))

This throws the exception because actually row has a string:

(my_project, 3)

And of course, it doesn't know what the heck is my_project. How to make it return results correctly or handle them correctly? For example it could return ('my_project', 3)

Source Link
mimic
  • 5.3k
  • 7
  • 63
  • 106
Loading