pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: ishapiro@cogitations.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Casting pairs of floating point variables as a point in plpgsql
Date: Thu, 21 Feb 2002 19:18:26 -0500
Message-ID: <12044.1014337106@sss.pgh.pa.us> (raw)
In-Reply-To: <758d9f0.0202181102.77fbc9ea@posting.google.com>
References: <758d9f0.0202181102.77fbc9ea@posting.google.com>

ishapiro@cogitations.com (Irv Shapiro) writes:
> How do I cast the logitude and latitude floatig point numbers, stored
> in my plpgsql variables into a point datatype so I can use it with the
> earthdistance function.

> I tried the following and it returns a syntax error on the "as":

> select cast((m_zip_info1, m_zip_info2) as point) <@>
>        cast((m_merchant_zip1, m_merchant_zip2) as point) into m_miles;

You cannot "cast" two floats into a point (a cast always operates on
a single data value).  However, a moment's perusal of pg_proc shows
that there is a function point(float8,float8), so this should work:

select point(m_zip_info1, m_zip_info2) <@>
       point(m_merchant_zip1, m_merchant_zip2) into m_miles;

			regards, tom lane



view thread (2+ messages)

Message-ID: <12044.1014337106@sss.pgh.pa.us>
Permalink:  ../12044.1014337106@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12044.1014337106@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ishapiro@cogitations.com
  Subject: Re: Casting pairs of floating point variables as a point in plpgsql
  In-Reply-To: <12044.1014337106@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox