PostgreSQL
 SQL >> Database >  >> RDS >> PostgreSQL

Rails: costanti in SELECT SQL e find_by_sql

Le costanti nella SELECT sono presenti, ma inspect di ActiveRecord mostra solo le colonne della tabella.

Esempio:

a = TableName.find_by_sql("SELECT id, name, 1 AS constant FROM table_name")

Puoi leggere a.first.constant, anche se il valore potrebbe essere restituito come stringa.