Re: Query a column with the same name as an operator

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: java(at)wagemaker(dot)co(dot)uk
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Query a column with the same name as an operator
Date: 2020-11-06 09:08:50
Message-ID: CABUevEwXcr079+tK8Ppq+dYtrigMwOVv2VndkwqUsADnTCeVyA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Nov 6, 2020 at 10:00 AM Java Developer <java(at)wagemaker(dot)co(dot)uk> wrote:
>
> Hello,
>
> I am trying to query a column from a table I migrated from my MYSQL
> into POSTGRESQL but I seem to be having issues with a few column names.
>
> the column name cast is also an operator, I think zone may also be a
> problem.
>
> MYSQL: OK
> SELECT id, start_date, local_time, country, city, region, temperature,
> cast, humidity, wind, weather, zone FROM w_records WHERE city =
> 'Edinburgh' AND start_date LIKE '%2020-11-01%' ORDER BY id DESC;
>
> I can run the SELECT * from FROM w_records WHERE city = 'Edinburgh' but
> the above does not work.
>
> Any idea how I can run a query that accept table name that is already a
> Operator?

Yes, cast is a keyword in SQL (not an operator). To use it as a column
name you have to quote it, like
SELECT "cast" FROM test
(and the same when you create the table, or indeed any references to the column)

zone is not, and should be fine.

--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jurrie Overgoor 2020-11-06 09:24:59 Re: Query a column with the same name as an operator
Previous Message Java Developer 2020-11-06 08:59:31 Query a column with the same name as an operator