sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Ignoring errors and continue on sql generate

Open SebastienMelki opened this issue 2 years ago • 1 comments

What do you want to change?

Hello,

I have multiple directories that contain .sql files that I would like sqlc to generate code from. Most of these files are "create table" files, but some of them are "create procedures" or "triggers". Sqlc errors out on those files when generating. I would like to be able to still get the generated code from the proper create table files. Is there a way to let 'sqlc generate' ignore errors and still generate the proper files that contain valid create table statements?

Thanks! image

What database engines need to be changed?

MySQL

What programming language backends need to be changed?

Go

SebastienMelki avatar Jul 23 '22 15:07 SebastienMelki

Is there a way to let 'sqlc generate' ignore errors and still generate the proper files that contain valid create table statements?

There currently isn't. The easiest workaround is to create a different folder with only the create table SQL files. Can you include some of the SQL files that are causing errors? It may be possible to successfully parse them.

kyleconroy avatar Jul 27 '22 05:07 kyleconroy

I'm having what is probably the same exact issue. I cloned our DB repos in an attempt to use sqlc (we also use skeema as did the poster). The files that are throwing errors are like this and throwing the same error as the poster: syntax error near "DELIMITER //".

DELIMITER //
CREATE DEFINER=`lamaster`@`%` PROCEDURE `activate_existing_crons`(IN var_cron_id INT)
BEGIN
        UPDATE `liveauct_crons`.`master_crons` SET active = 1 WHERE cron_id = var_cron_id;
    END//
DELIMITER ;

I have fixed this myself with a bash script to my liking. It just deletes the bad files since sqlc doesn't need them. Although maybe it would need them if I tried writing a query that called the functions they defined.

Gobd avatar Mar 23 '23 23:03 Gobd