I'm using PostgreSQL 9.5.3 and I'm trying to select all users that have an age of over twenty. I have constructed a SQLFiddle that shows the error:
http://sqlfiddle.com/#!15/5cd52/3
SNIPPET:
Schema:
CREATE TABLE users (
name text,
birthdate bigint
);
INSERT INTO users values('Chris', 774532800000);
SQL:
SELECT u.*, age(TO_TIMESTAMP(u.birthdate / 1000)) as age from users u
WHERE age > 20
ERROR:
ERROR: column "age" does not exist Position: 77
The reason that I'm deviding by 1000 is because my dates are all stored using milliseconds
as that's the default by Firebase. This postgreSQL database is used to handle more complex queries that Firebase couldn't.