-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Syntax error when using queryInterface.createFunction() #11312
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
Comments
Hello!
Can you please post exactly what SQL you wanted to see instead? |
What I would like to see happen instead is: If I select "language=sql" the function gets created without problem and if I check it in pgAdmin I will see:
Note: there is no BEGIN and END keywords in the function - unlike when I set "language=plpgsql". I suspect that the error message points to the first select where there is a BEGIN that is not expected because of language=sql. |
Please tell me if I understood correctly. What was generated by SequelizeCREATE FUNCTION building.getBuildingIds(IN longitude float, IN latitude float) RETURNS TABLE(geometry geometry, building_id uuid, distance double precision) AS $func$ BEGIN select
intersection.geometry,
intersection.building_id,
ST_Distance(intersection.geometry, ST_MakePoint(longitude, latitude)::geography) as distance
from (
select
building_id,
geometry
from building.building
where ST_Intersects (
geometry,
ST_Buffer(ST_MakePoint(longitude, latitude)::geography, 1)::geometry
)
) as intersection
order by distance asc; END; $func$ language 'sql'; What should have been generated insteadCREATE FUNCTION building.getBuildingIds(IN longitude float, IN latitude float) RETURNS TABLE(geometry geometry, building_id uuid, distance double precision) AS $func$ select
intersection.geometry,
intersection.building_id,
ST_Distance(intersection.geometry, ST_MakePoint(longitude, latitude)::geography) as distance
from (
select
building_id,
geometry
from building.building
where ST_Intersects (
geometry,
ST_Buffer(ST_MakePoint(longitude, latitude)::geography, 1)::geometry
)
) as intersection
order by distance asc; $func$ language 'sql'; Is this correct? (I simply deleted |
Yes, Pedro, you understood correctly. The latter is what I would like to have generated. If there are no more BEGIN and END, then, the syntax error should be gone. It would be great to have that fixed in a new version as soon as possible. Thank you very much! |
I could make the merge request. Would be the solution to remove the insertion of |
Hello @flashspys, that is great!
If I understood correctly, this problem does not happen in other language choices, therefore I think this is a bug of the |
This sounds very good to me. Thank you guys! |
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
What are you doing?
I am writing a queryInterface.createFunction() in a migration file that looks like this:
When I run the migration I get the following error message:
What do you expect to happen?
I expect the same CREATE FUNCTION statement as above but without the BEGIN and END since I use language=sql (if I specify language=plpgsql then the described error doesn't happen).
Environment
PostgreSQL, Sequelize version: 5.13.1
The text was updated successfully, but these errors were encountered: