salut,

ma table de données est sur postgresql version 11, elle contient une colonne type json.
Via l'utilisation de python, je voudrai sélectionner les données de cette colonne et l'enregistre dans un fichier externe format json.
mais je trouve des difficultés afin de réaliser cela.
mon code est:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import psycopg2
from app import db
from models import Geotab 
 
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.sql import select
 
 
 
 
try:
    connection = psycopg2.connect(user = "postgres",
                                  password = "admin",
                                  host = "127.0.0.1",
                                  port = "5432",
                                  database = "catalogue")
    cursor = connection.cursor()
    # Print PostgreSQL Connection properties
    print ( connection.get_dsn_parameters(),"\n")
    # Print PostgreSQL version
    cursor.execute("SELECT version();")
    record = cursor.fetchone()
    print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
    print ("Error while connecting to PostgreSQL", error)
 
 
 
data=db.session.query(Geotab).\
       filter(Geotab.dataJson[''])   #.astext.cast(JSON))
print (data)
voilà qu'est ce qu'il m'affiche:

user=postgres password=admin host=127.0.0.1 port=5432 dbname=catalogue
{'user': 'postgres', 'dbname': 'catalogue', 'host': '127.0.0.1', 'port': '5432', 'tty': '', 'options': '', 'sslmode': 'prefer', 'sslcompression': '0', 'krbsrvname': 'postgres', 'target_session_attrs': 'any'}

You are connected to - ('PostgreSQL 11.4, compiled by Visual C++ build 1914, 64-bit',)

SELECT geocat.id AS geocat_id, geocat.url AS geocat_url, geocat.date AS geocat_date, geocat."dataJson" AS "geocat_dataJson"
FROM geocat
WHERE geocat."dataJson" -> %(dataJson_1)s
merci d'avance d'avoir m'aider