I have the following SQL Query which I run in PgAdmin:
WITH TABLE1 AS
( SELECT int1, int2, int3 FROM atbl
)
SELECT int1, <complex computation involving a large number of values of int2 and int3 from TABLE1>
FROM TABLE1
The result of running it is an error message:
ERROR:  syntax error at or near "WITH"
LINE 1: WITH TABLE1 AS
Why does this happen? The with statement should be available for PostgreSQL:
http://www.postgresql.org/docs/8.4/static/queries-with.html
It is understood that this version is lower than 8.4. Is there an alternative to using WITH to ach开发者_运维百科ive the same results?
I found this and this helpful. and make sure your using a version >= 8.4 as that's when this was introduced. Not having a ; shouldn't be an issue.
Your syntax looks correct though... this definitely works.
WITH table1 AS (
SELECT * FROM atbl
)
select * from table1
So I'd check the version you are running. as that give the error your are experiencing.
You can replace it with the following:
SELECT int1, 
       (complex computation involving a large number of values of int2 and int3 from TABLE1)
FROM ( 
   SELECT int1, int2, int3 
   FROM atbl
) table1
What's wrong with simple SQL?
SELECT 
  int1, 
  <complex computation involving a large number of values of int2 and int3 from atbl>
FROM 
  atbl;
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论