pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedarrays and polygons
4+ messages / 3 participants
[nested] [flat]
* arrays and polygons
@ 2004-02-13 10:25 David <de4@kent.ac.uk>
0 siblings, 1 reply; 4+ messages in thread
From: David @ 2004-02-13 10:25 UTC (permalink / raw)
To: pgsql-sql
Hi there i am having problems inserting an array of polygons into a table, i
have added the column using:
ALTER TABLE species ADD COLUMN location polygon[];
this works fine, but when i try
INSERT INTO species (location) VALUES ('{((432,89), (45,87), (89,87)),
((54,78), (34,98))};
I get the following error message:
ERROR: Bad polygon external representation '((432'
Where am i going wrong, all help is much appreciated DAvid
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: arrays and polygons
@ 2004-02-13 15:02 Tom Lane <tgl@sss.pgh.pa.us>
parent: David <de4@kent.ac.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2004-02-13 15:02 UTC (permalink / raw)
To: David <de4@kent.ac.uk>; +Cc: pgsql-sql
"David" <de4@kent.ac.uk> writes:
> ALTER TABLE species ADD COLUMN location polygon[];
> INSERT INTO species (location) VALUES ('{((432,89), (45,87), (89,87)),
> ((54,78), (34,98))};
I think you'd need to double-quote each polygon within the array
literal.
'{"((432,89), (45,87), (89,87))", "..."}'
The array parser doesn't think parens are special, so it's not going to
magically distinguish array commas from polygon commas for you.
BTW, if you are using 7.4, the ARRAY[] constructor syntax might be
easier to use.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: arrays and polygons
@ 2004-02-13 16:33 Joe Conway <mail@joeconway.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Joe Conway @ 2004-02-13 16:33 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: David <de4@kent.ac.uk>; pgsql-sql
Tom Lane wrote:
> "David" <de4@kent.ac.uk> writes:
>>INSERT INTO species (location) VALUES ('{((432,89), (45,87), (89,87)),
>>((54,78), (34,98))};
>
> I think you'd need to double-quote each polygon within the array
> literal.
>
> '{"((432,89), (45,87), (89,87))", "..."}'
>
> The array parser doesn't think parens are special, so it's not going to
> magically distinguish array commas from polygon commas for you.
>
> BTW, if you are using 7.4, the ARRAY[] constructor syntax might be
> easier to use.
FWIW, here's what it would look like in 7.4.x:
regression=# select ARRAY['((432,89), (45,87), (89,87))'::polygon,
'((432,89), (45,87), (89,87))'];
array
-------------------------------------------------------------
{"((432,89),(45,87),(89,87))","((432,89),(45,87),(89,87))"}
(1 row)
You need to explicitly cast at least the first polygon in order to get
an array of polygons (versus an array of text).
HTH,
Joe
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: arrays and polygons
@ 2004-02-13 17:00 David <de4@kent.ac.uk>
parent: Joe Conway <mail@joeconway.com>
0 siblings, 0 replies; 4+ messages in thread
From: David @ 2004-02-13 17:00 UTC (permalink / raw)
To: Joe Conway <mail@joeconway.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Thanks to you both that helped enormously,
Dave
----- Original Message -----
From: "Joe Conway" <mail@joeconway.com>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: "David" <de4@kent.ac.uk>; <pgsql-sql@postgresql.org>
Sent: Friday, February 13, 2004 4:33 PM
Subject: Re: [SQL] arrays and polygons
> Tom Lane wrote:
> > "David" <de4@kent.ac.uk> writes:
> >>INSERT INTO species (location) VALUES ('{((432,89), (45,87), (89,87)),
> >>((54,78), (34,98))};
> >
> > I think you'd need to double-quote each polygon within the array
> > literal.
> >
> > '{"((432,89), (45,87), (89,87))", "..."}'
> >
> > The array parser doesn't think parens are special, so it's not going to
> > magically distinguish array commas from polygon commas for you.
> >
> > BTW, if you are using 7.4, the ARRAY[] constructor syntax might be
> > easier to use.
>
> FWIW, here's what it would look like in 7.4.x:
>
> regression=# select ARRAY['((432,89), (45,87), (89,87))'::polygon,
> '((432,89), (45,87), (89,87))'];
> array
> -------------------------------------------------------------
> {"((432,89),(45,87),(89,87))","((432,89),(45,87),(89,87))"}
> (1 row)
>
> You need to explicitly cast at least the first polygon in order to get
> an array of polygons (versus an array of text).
>
> HTH,
>
> Joe
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2004-02-13 17:00 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-13 10:25 arrays and polygons David <de4@kent.ac.uk>
2004-02-13 15:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-02-13 16:33 ` Joe Conway <mail@joeconway.com>
2004-02-13 17:00 ` David <de4@kent.ac.uk>
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