Thread: Expression matching related question

Expression matching related question

From
Peter Hoskin
Date:
Hi,

I wish to do a query such as:
SELECT * FROM table WHERE column='something' AND column2='something
else' AND (network='0' OR (left=0 AND network>0));

However, when I execute this in phppgadmin I'm told there is an error
around the = character in left=0. Can't seem to figure the syntax.

Help would be appreciated.

Regards,
Peter Hoskin

Re: Expression matching related question

From
Peter Hoskin
Date:
I should of mentioned, left is a bigint and network is an integer

Peter Hoskin wrote:
> Hi,
>
> I wish to do a query such as:
> SELECT * FROM table WHERE column='something' AND column2='something
> else' AND (network='0' OR (left=0 AND network>0));
>
> However, when I execute this in phppgadmin I'm told there is an error
> around the = character in left=0. Can't seem to figure the syntax.
>
> Help would be appreciated.
>
> Regards,
> Peter Hoskin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>

Re: Expression matching related question

From
Michael Fuhr
Date:
On Mon, Apr 10, 2006 at 06:23:01AM +1000, Peter Hoskin wrote:
> I wish to do a query such as:
> SELECT * FROM table WHERE column='something' AND column2='something
> else' AND (network='0' OR (left=0 AND network>0));
>
> However, when I execute this in phppgadmin I'm told there is an error
> around the = character in left=0. Can't seem to figure the syntax.

If you're using reserved words like table, column, and left as
identifiers then you'll need to double-quote them.  Better yet,
avoid using reserved words as identifiers.

--
Michael Fuhr

Re: Expression matching related question

From
Tom Lane
Date:
Peter Hoskin <peterh@criten.org> writes:
> I wish to do a query such as:
> SELECT * FROM table WHERE column='something' AND column2='something
> else' AND (network='0' OR (left=0 AND network>0));

> However, when I execute this in phppgadmin I'm told there is an error
> around the = character in left=0. Can't seem to figure the syntax.

LEFT is a reserved word, isn't it?  If you're going to insist on naming
a column "left", you'll have to double-quote the name every time.

            regards, tom lane