Skip to content

Instantly share code, notes, and snippets.

@apennebaker-ni
Created May 21, 2015 17:41
Show Gist options
  • Select an option

  • Save apennebaker-ni/9ea60845c040226822aa to your computer and use it in GitHub Desktop.

Select an option

Save apennebaker-ni/9ea60845c040226822aa to your computer and use it in GitHub Desktop.

Code:

-- work around JDBC 'A result was returned when none was expected.'
DO '
BEGIN
  -- fix broken nextval due to poorly written 20140320100000_CreateAdminUserRoleTables.sql
  PERFORM setval(''admin_user_role_groups_id_seq'', 1 + COALESCE(MAX(id), 0), FALSE) FROM admin_user_role_groups;
END; ';

Trace:

ERROR: unterminated quoted string at or near "' BEGIN PERFORM setval(''admin_user_role_groups_id_seq'', 1 + COALESCE(MAX(id), 0), FALSE) FROM admin_user_role_groups"
  Position: 4
@apennebaker-ni
Copy link
Copy Markdown
Author

JDBC is really quite dumb, mistakenly thinking that the semicolon after END terminates the begin, because of a line break.

The solution is to write the do ... end all in a single line:

-- work around JDBC 'A result was returned when none was expected.'
-- fix broken nextval due to poorly written 20140320100000_CreateAdminUserRoleTables.sql
DO 'BEGIN PERFORM setval(pg_get_serial_sequence(''admin_user_role_groups'', ''id''), 1 + COALESCE(MAX(id), 0), FALSE) FROM admin_user_role_groups; END;';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment