Re: How do I create a box from fields in a table?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Rob Richardson <RDRichardson(at)rad-con(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I create a box from fields in a table?
Date: 2013-10-17 21:57:44
Message-ID: CAHyXU0zt=jYU+wuSHvgZcyFY=3-GuzG940fbgpU5OHo9zrA1DA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 17, 2013 at 4:04 PM, Rob Richardson
<RDRichardson(at)rad-con(dot)com> wrote:
> I need to determine whether a given pair of coordinates is inside a given rectangle. According to the documentation, PostgreSQL provides the box and point types and a "contains" operator that will be perfect for this. However, the example provided in the documentation only shows the creation of boxes and points from constant values. So, the following query works:
>
> select tran_car_identification, box '((0, 1), (2, 3))' from transfer_car
>
> But if I try to use a field from the transfer_car table, it doesn't work:
>
> select tran_car_identification, box '((location, 1), (2, 3))' from transfer_car
>
> That gives me an "invalid input syntax for type box" error.
>
> How do I create a box object using data from the transfer_car table?

you have to construct the string. this is somewhat baroque by modern
postgres standards but should work:

select tran_car_identification, format('((%s, 1), (2, 3))',
location)::box from transfer_car;

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Huang, Suya 2013-10-17 22:13:43 [ADMIN] what's the efficient/safest way to convert database character set ?
Previous Message Rob Richardson 2013-10-17 21:04:36 How do I create a box from fields in a table?