Search code examples
postgresqlcreate-view

Error with creating view in PostgreSQL


Here's the code:

CREATE OR REPLACE VIEW skats_4 AS SELECT count(datums) AS 
2014_gada_pieteikumi from pieteikums where date_part('YEAR', 
datums)=2014;

I keep getting error with text "syntax error near 2014" (the "2014_gada_pieteikumi"). I don't see what is wrong.


Solution

  • Label should not to start by number. Use double quotes or rename label

    postgres=# select 10 as 2014_some;
    ERROR:  syntax error at or near "2014"
    LINE 1: select 10 as 2014_some;
                         ^
    Time: 0.647 ms
    postgres=# select 10 as "2014_some";
     2014_some 
    ───────────
            10
    (1 row)