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

Field defined as text being interpreted as integer #220

Open
robintw opened this issue Oct 7, 2024 · 0 comments
Open

Field defined as text being interpreted as integer #220

robintw opened this issue Oct 7, 2024 · 0 comments

Comments

@robintw
Copy link

robintw commented Oct 7, 2024

I have a function layer in pg_tileserv that uses a function that is defined as:

FUNCTION public.blah(
                    z integer, x integer, y integer,
                    l float8,
                    t float8,
                    b float8,
                    r float8,
                    scenario text,  
                    source integer,
		   amenity text)
RETURNS bytea

I call it like this:

http://localhost/public.blah/12/2000/1382.pbf?l=-4&t=50&b=50.5&r=-3&amenity=003&scenario=scen1&source=2

The amenity parameter is defined in the function as text, but by the time it gets to the function it seems to be being interpreted as an integer. I've had to add a ::text type cast inside the function but - more importantly - this is causing me problems when the input is a value with leading zeros, like 003. This is interpreted as an integer of 3 and then converted back to '3' as text, which makes my WHERE clause fail as the database contains 003.

I've found a workaround by changing the URL to have the value with leading zeros in quotes:

http://localhost/public.blah/12/2000/1382.pbf?l=-4&t=50&b=50.5&r=-3&amenity='003'&scenario=scen1&source=2

which then gets passed through correctly as a string.

Do you have any idea where this incorrect type conversion is happening? I'm pretty sure it's not in my Javascript code that is setting the URLs for my map - as the Network tab in Developer Tools show that the URL has 003 in it. So I think it must be somewhere in pg_tileserv or my PostGIS function.

Any ideas for where to look would be very helpful

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

1 participant