2

I am having difficulty writing a nested postgis query. I have a single table from which I need to create a view in PostgreSQL.

I have created the view with the following command

create view rrop08.rrop08_lws_f AS
select * from rrop08.rrop08_gk3_polygon 
where planznr='04.01' OR planznr ='04.02';

The problem here is that the table contains another field called "bez". I need to carry out the first query but also with bez=0; so that none of the 04.01 or 04.02 rows have a bez value other than 0.

I have tried this...

create view rrop08.rrop08_lws_f AS
select * from rrop08.rrop08_gk3_polygon 
where planznr='04.01' OR planznr ='04.02' AND bez=0;

but this retrieves all rows with bez=0 and not just the 04.01 or 04.02 ones. I need to first select 04.01 or 04.02 and then on this query get those with bez=0...ie.nested.

I ́m a bit lost on how to do this.

THanks for any help,

Rob

taudorf
1,6652 gold badges16 silver badges29 bronze badges
asked Jul 11, 2012 at 9:12

1 Answer 1

3

Use parenthesis to group the logical expressions or they usually get evaluated from left to right like you experienced:

create view rrop08.rrop08_lws_f AS select * from rrop08.rrop08_gk3_polygon where (planznr='04.01' OR planznr ='04.02') AND bez=0;
answered Jul 11, 2012 at 9:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.