Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WITH statement not working in Postgresql

Tags:

sql

postgresql

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 achive the same results?

like image 841
mstaniloiu Avatar asked Sep 13 '26 20:09

mstaniloiu


1 Answers

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.

like image 155
Mr Shoubs Avatar answered Sep 15 '26 09:09

Mr Shoubs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!