Thread: Problem with extract function ?

Problem with extract function ?

From
Esteban Zimanyi
Date:
Is there a problem with the extract function as shown below? In the SELECT clause it should be possible to rename any column by adding after the column "as xxx" or simply "xxx".

------------------------------------------------------
NorthwindDW=# select current_date today , extract(week from current_date) weeknbyear;
   today    |  weeknbyear
------------+-------------
 2020-11-12 |          46
(1 row)

NorthwindDW=# select current_date as today , extract(week from current_date) as weeknbyear;
2020-11-12 13:25:21.217 CET [20130] ERROR:  syntax error at or near "weeknbyear" at character 67
2020-11-12 13:25:21.217 CET [20130] STATEMENT:  select current_date as today , extract(week from current_date) as weeknbyear;
ERROR:  syntax error at or near "weeknbyear"
LINE 1: ...ate as today , extract(week from current_date) as weeknbyear...
                                                             ^
NorthwindDW=# select current_date as today , extract(week from current_date) as xxx;
2020-11-12 13:25:37.817 CET [20130] ERROR:  syntax error at or near "xxx" at character 67
2020-11-12 13:25:37.817 CET [20130] STATEMENT:  select current_date as today , extract(week from current_date) as xxx;
ERROR:  syntax error at or near "xxx"
LINE 1: ...rent_date as today , extract(week from current_date) as xxx;
                                                                   ^
NorthwindDW=# select version();
                                             version
-------------------------------------------------------------------------------------------------
 PostgreSQL 13rc1 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit
(1 row)
------------------------------------------------------

Regards

Esteban

Re: Problem with extract function ?

From
Erik Rijkers
Date:
On 2020-11-12 13:26, Esteban Zimanyi wrote:

>  PostgreSQL 13rc1 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu

Did you notice Postgres 13 is available?

I can't reproduce this (Debian with postgres 12 or 13)


Erik





Re: Problem with extract function ?

From
Tom Lane
Date:
Esteban Zimanyi <ezimanyi@ulb.ac.be> writes:
> NorthwindDW=# select current_date as today , extract(week from
> current_date) as weeknbyear;
> 2020-11-12 13:25:21.217 CET [20130] ERROR:  syntax error at or near
> "weeknbyear" at character 67

That works fine for me.  However, I can reproduce the syntax error
if I misspell "as":

# select current_date as today , extract(week from
current_date) ss weeknbyear;
ERROR:  syntax error at or near "weeknbyear"
LINE 2: current_date) ss weeknbyear;
                         ^

This leads me to suspect that you have some weird invisible character
(non-break space, zero-width space, etc) adjacent to "as".  Postgres
is not terribly forgiving of non-ASCII whitespace.

            regards, tom lane



Re: Problem with extract function ?

From
Esteban Zimanyi
Date:
Many thanks to both of you Tom and Eric for your prompt response.

I installed 13.1 and now the problem is solved. The consequence of this exchange is that I can now test MobilityDB on the brand new version of PostgreSQL :-)

Regards

On Thu, Nov 12, 2020 at 4:32 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Esteban Zimanyi <ezimanyi@ulb.ac.be> writes:
> NorthwindDW=# select current_date as today , extract(week from
> current_date) as weeknbyear;
> 2020-11-12 13:25:21.217 CET [20130] ERROR:  syntax error at or near
> "weeknbyear" at character 67

That works fine for me.  However, I can reproduce the syntax error
if I misspell "as":

# select current_date as today , extract(week from
current_date) ss weeknbyear;
ERROR:  syntax error at or near "weeknbyear"
LINE 2: current_date) ss weeknbyear;
                         ^

This leads me to suspect that you have some weird invisible character
(non-break space, zero-width space, etc) adjacent to "as".  Postgres
is not terribly forgiving of non-ASCII whitespace.

                        regards, tom lane