Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry subtype not inferred for function returns #41

Open
apjoseph opened this issue Jun 3, 2021 · 3 comments
Open

Geometry subtype not inferred for function returns #41

apjoseph opened this issue Jun 3, 2021 · 3 comments

Comments

@apjoseph
Copy link

apjoseph commented Jun 3, 2021

With

    "postgraphile": "4.12.2",
    "@graphile/postgis": "0.1.0",

The following function will return a geometry interface as a return type instead of a point geometry. This is particularly frustrating for computed columns on tables (for example generating a centroid for a polygon geometry).

CREATE FUNCTION myschema.mytable_pos(mytable myschema.mytable) RETURNS geometry(Point,4326) AS $$
SELECT st_pointonsurface(geom)
$$ LANGUAGE sql STABLE
@benjie
Copy link
Member

benjie commented Jun 3, 2021

Annoyingly this is a limitation of PostgreSQL. It may look like it returns that type in your definition but if you look in a pg_dump of the database you’ll notice the modifier is dropped. PostgreSQL does not store this.

@apjoseph
Copy link
Author

apjoseph commented Jun 3, 2021

@benjie ah, ok so postgres is not even storing the return type modifiers -that is bizarre behavior on the part of postgres as type modifiers are pretty important!

Maybe for these types of cases an @forceType tag would be beneficial so that the modifiers could be manually specified.

@benjie
Copy link
Member

benjie commented Jun 3, 2021

Yeah, implementing it would be tricky since the modifier is a 4 byte binary value under the hood. Effectively you’d have to encode the human readable version back to the byte representation so that PostGraphile could convert it back again; and it would only be useful for postgis since every type processes it’s modifiers differently. If you’re interested in taking this on; here’s a starting point:

https://github.com/graphile/postgis/blob/master/src/utils.ts#L4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants