sql >> Database teknologi >  >> RDS >> PostgreSQL

Syntaks for row_to_json med sqlalchemy

Din forespørgsel genererer en forkert SQL

SELECT row_to_json(SELECT ... FROM foo) AS details
FROM (SELECT ... FROM foo) AS details_foo_row_q

Det burde være

SELECT row_to_json(details_foo_row_q) AS details
FROM (SELECT ... FROM foo) AS details_foo_row_q

Du skal bruge select som literal_column a>

from sqlalchemy.sql.expression import literal_column

details_foo_q = select([
    func.row_to_json(literal_column(details_foo_row_q.name)).label('details')
]).select_from(details_foo_row_q).where(
    details_foo_row_q.c.bar_id == Bar.id
).alias('details_foo_q')


  1. Oracle Database Enforce CHECK på flere tabeller

  2. Sådan omdøbes en Oracle XMLTYPE-node

  3. XA vs. Ikke-XA JDBC-driverydelse?

  4. På grund af Null-værdi genudfyldes data ikke