Fix JSON conversion of the table name which is also a keyword (#133)

Similarly to escape the table name in the SELECT command query, here we
escape the table name with apostrophes.
In fact, `to_json()` raised a "Syntax error" for table that uses a keyword as
its name.
pull/139/head
Santo Cariotti 2 years ago committed by GitHub
parent f96a573502
commit de0d57c9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -482,7 +482,7 @@ impl PostgresPool {
) -> anyhow::Result<Vec<serde_json::Value>> {
let query = if let Some(filter) = filter {
format!(
r#"SELECT to_json({table}.*) FROM "{database}"."{table_schema}"."{table}" WHERE {filter} LIMIT {limit} OFFSET {page}"#,
r#"SELECT to_json("{table}".*) FROM "{database}"."{table_schema}"."{table}" WHERE {filter} LIMIT {limit} OFFSET {page}"#,
database = database.name,
table = table.name,
filter = filter,
@ -492,7 +492,7 @@ impl PostgresPool {
)
} else {
format!(
r#"SELECT to_json({table}.*) FROM "{database}"."{table_schema}"."{table}" LIMIT {limit} OFFSET {page}"#,
r#"SELECT to_json("{table}".*) FROM "{database}"."{table_schema}"."{table}" LIMIT {limit} OFFSET {page}"#,
database = database.name,
table = table.name,
table_schema = table.schema.clone().unwrap_or_else(|| "public".to_string()),

Loading…
Cancel
Save