SELECT *, date_start + (day_interval || ' day')::interval AS date_end FROM tariffs WHERE date_start<=date_end 

SQLSTATE [42703]: Undefined column: 7 ERROR: column "date_end" does not exist

How to fix?

  • You don't have a column named date_end in the table. In the where part you can refer only to the columns that exist in the table. (since the where part is executed before the start of the select part) If you need to compare with the result of evaluating an expression that you called date_end in the select list, just write the expression in where. - Mike
  • Do you want a calculated column to be used in a where clause or something? will not work. where is executed earlier than the select instruction, duplicate the expression - teran
  • I really don't understand this condition. you add a certain value to date_start, then you try to check that the result is greater than the same date_start. This condition will not be satisfied only if day_interval is negative, so it will be much easier to check where day_interval>=0 - Mike
  • it's decided! thanks!) - darkfriend

1 answer 1

 SELECT *, date_start + (day_interval || ' day')::interval AS date_end FROM tariffs WHERE date_start + (day_interval || ' day')::interval<current_timestamp 

that's so decided. Thank!