Skip to content

Commit 39331a5

Browse files
committed
Recognize UPDATE FOR tokens
1 parent 762690d commit 39331a5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,27 @@ mod tests {
456456
assert_eq!(format(input, &QueryParams::None, &options), expected);
457457
}
458458

459+
#[test]
460+
fn it_formats_select_with_for_update_of() {
461+
let input: &'static str = "SELECT id FROM users WHERE disabled_at IS NULL FOR UPDATE OF users SKIP LOCKED LIMIT 1";
462+
let options = FormatOptions::default();
463+
let expected = indoc!(
464+
"
465+
SELECT
466+
id
467+
FROM
468+
users
469+
WHERE
470+
disabled_at IS NULL
471+
FOR UPDATE
472+
OF users SKIP LOCKED
473+
LIMIT
474+
1"
475+
);
476+
477+
assert_eq!(format(input, &QueryParams::None, &options), expected);
478+
}
479+
459480
#[test]
460481
fn it_formats_limit_with_two_comma_separated_values_on_single_line() {
461482
let input = "LIMIT 5, 10;";

src/tokenizer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ fn get_top_level_reserved_token<'a>(
481481
last_reserved_top_level_token: Option<Token<'a>>,
482482
) -> impl Parser<&'a str, Token<'a>, ContextError> {
483483
move |input: &mut &'a str| {
484-
let uc_input: String = get_uc_words(input, 3);
484+
let uc_input: String = get_uc_words(input, 4);
485485
let mut uc_input = uc_input.as_str();
486486

487487
// First peek at the first character to determine which group to check
@@ -522,6 +522,14 @@ fn get_top_level_reserved_token<'a>(
522522
'F' => alt((
523523
terminated("FETCH FIRST", end_of_word),
524524
terminated("FROM", end_of_word),
525+
terminated(
526+
(
527+
"FOR ",
528+
alt(("UPDATE", "NO KEY UPDATE", "SHARE", "KEY SHARE")),
529+
)
530+
.take(),
531+
end_of_word,
532+
),
525533
))
526534
.parse_next(&mut uc_input),
527535

0 commit comments

Comments
 (0)