sql >> Databasteknik >  >> RDS >> PostgreSQL

Syntax för row_to_json med sqlalchemy

Din fråga genererar en felaktig SQL

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

Det borde vara

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

Du måste använda 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. Konvertera från datum till epok-Oracle

  2. Hur man genererar alla begränsningsskript

  3. Skapa tabell i MySQL som matchar en annan tabell?

  4. Infoga skrapad tabelldata direkt i PostgreSQL db