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

Pugsql chokes on normal comments interspersed in the sql file #62

Open
ou-vlakvark opened this issue May 22, 2022 · 5 comments
Open

Pugsql chokes on normal comments interspersed in the sql file #62

ou-vlakvark opened this issue May 22, 2022 · 5 comments

Comments

@ou-vlakvark
Copy link

pugsql raises the following error if there are any normal comments in the sql code (unless they are between the :name special comment and the actual sql query.
ValueError: Statement must have a name.

Is this the correct behaviour? Would it not be desirable to be able to comment out sections of the sql file or add section comments etc?

@mcfunley
Copy link
Owner

Can you paste a query that fails?

@ou-vlakvark
Copy link
Author

Hi, thanks for your quick response. This was my first time trying to use pugsql so maybe I am just doing something wrong. But here is my failing query file:
start of file ---------------------------------------
/*
pugsql seems to choke on this comment
*/

-- pugsql seems to choke on a single-line comment as well

-- :name greet :one
/*
pugsql handles this comment
*/
select 'hello' as greeting;

-- :name get_user_42 :one
-- pugsql handles this comment
select username from user where id = 42;

-- :name get_user_with_id :one
select username from user where id = :id;
end fo file-------------------------------

@ou-vlakvark
Copy link
Author

Adding the following lines to the head of the above file seems to satisfy pugsql:

:name dummy_query :one
select 'this stops pugsql choking on the following comments' as kludge;

@ou-vlakvark
Copy link
Author

I have edited the description of the error to be more accurate

@mcfunley
Copy link
Owner

I see, currently pugsql needs the metadata for the query (the :name, and so on) to be in the first comment block in the file, using the -- comment syntax. There is a confusing edge here where pugsql will accept:

--- not metadata
--- :name foo
select 1;

but not:

--- not metadata

--- :name foo
select 1;

We should resolve that (probably backwards compatible with how it works now) so that it's no longer whitespace significant.

I could see also supporting a /* */ style comment, which we don't currently.

There are probably also some ways the error messages could be more helpful here.

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