Misudka
Misudka

Reputation: 1

Postgres - TypeError: tabulate() got an unexpected keyword argument 'colalign'

I have problem in Postgres 16.2 with plpython procedure and library tabulate.

I created procedure:

CREATE OR REPLACE PROCEDURE dpl.__test_tabulate()
LANGUAGE plpython3u AS $plpy$
from tabulate import tabulate
plpy.info('%s' % tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
$plpy$;

But when I run it in psql, I get the error:

database=# CALL dpl.__test_tabulate();
ERROR:  TypeError: tabulate() got an unexpected keyword argument 'colalign'
CONTEXT:  Traceback (most recent call last):
  PL/Python function "__test_tabulate", line 4, in <module>
    plpy.info('%s' % tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
PL/Python procedure "__test_tabulate"
database=#

The my postgres runs on RHEL 8.9.

On the RHEL is Python 3.9 installed (with 3.6 together).

When I run this procedure in Python 3.9, it works:

# python
Python 3.9.18 (main, Sep 22 2023, 18:24:59)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tabulate import tabulate
>>> print(tabulate([["one", "two"], ["three", "four"]], colalign=("right",)))
-----  ----
  one  two
three  four
-----  ----

But Postgres 16.2 use python 3.6, and there the procedure does not work. And when I run the procedure in RHEL python 3.6, it does not works too.

How do I force Postgres to use python 3.9 instead of 3.6 version?

postgres@server:/var/lib/pgsql # python3 -V
Python 3.9.18
postgres@server:/var/lib/pgsql # pip show tabulate
Name: tabulate
Version: 0.9.0
Summary: Pretty-print tabular data
Home-page:
Author:
Author-email: Sergey Astanin <[email protected]>
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by: apache-airflow
postgres@server:/var/lib/pgsql # psql -d database
psql (16.2)
Type "help" for help.

database=# select pyver();
                  pyver
-----------------------------------------
 3.6.8 (default, Jan  5 2024, 09:14:44) +
 [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)]
(1 row)

database=#

The problem was found after upgrade from version 13.5 to new version 16.2. Setup of the upgrade>

time /usr/pgsql-16/bin/pg_upgrade --jobs=16 -d /postgres/pgsql/database/data13 -D /postgres/pgsql/database/data16 -b /usr/pgsql-13/bin/ -B /usr/pgsql-16/bin/ --link

The main DB has 70TB size.

Installation packages was downloaded from this repository: https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8.9-ppc64le/

Upvotes: 0

Views: 197

Answers (1)

Misudka
Misudka

Reputation: 1

In another forum where I asked about my problem, I received information that RHEL 8 has Python 3.6 by default.

That's enough of an answer for me. I was worried that I had made a mistake during the upgrade. Now I know I didn't make a mistake during the upgrade.

One way to change the Python used is to recompile plpython3u. But experts strongly do not recommend this. So the only possibility is to upgrade RHEL to version 9. But I can do that when Postgres 16 is also available for the ppc64le platform.

So thank you all.

Upvotes: 0

Related Questions