1

I am trying to construct a statement that dynamically builds the syntax to properly query a box data type in postgres.

It looks something like the following:

Note: foo1 is an integer value

with a as (
  select foo1 from foo where id = 1), 
     b as (
  select a, b, c from bar where a && '''('||a.foo1||',0,'||a.foo1||',0)''')
select * from b;

The above query yields: ERROR: invalid input syntax for type box: "'("

Is it possible to build this type of query dynamically?

See the answer Another similar StackOverflow question that shows how you would normally query the box data type.

Community
  • 1
  • 1
vette99
  • 25
  • 5

1 Answers1

1

You can simplify the whole query:

SELECT b.a, b.b, b.c
FROM   foo f
JOIN   bar b ON b.a && box(point(f.foo1,0), point(f.foo1,0))
WHERE  f.id = 1;
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228