Skip to content

Postgres support (basic syntax) #42

@nene

Description

@nene

Basic syntax

  • Keywords
    • Some reserved keywords can be used in implicit alias names
    • All reserved keywords can be used in explicit AS alias names
    • Restrict certain keywords as function or type names
    • Up-to-date keywords list for PostgreSQL 16
  • Comments
    • Standard SQL line comments: -- foo
    • Multiline comments: /* blah */
    • Nested multiline comments: /* foo /*blah*/ bar */
    • Does not support #-comments
  • identifiers
    • Identifiers can start with unicode letter or underscore
    • Subsequent characters can be letters, underscores, digits (0-9) and $.
    • Quoted identifiers "foo bar"
    • Unicode identifiers U&"d\0061t\+000061"
    • Unicode identifiers with custom escaping U&"d!0061t!+000061" UESCAPE '!'
  • String literals
    • Single-quoted strings
    • Quote escaping with repeating: 'foo''bar'
    • String concatenation with whitespace: 'foo'\n'bar' (but not 'foo' 'bar', must have at least on \n, then any number of spaces can also be included. Can also include line comments, but no block comments.)
      • in plain single-quoted strings
      • in C-style escaped strings
      • in Unicode strings
    • C-style escapes: E'foo\nbar'
      • \b, \f, \n, \r, \t
      • octal: \o, \oo, \ooo
      • hex: \xh, \xhh
      • unicode: \uxxxx, \Uxxxxxxxx
      • quote escaping with both \' and '',
    • Unicode strings: U&'d\0061t\+000061'
    • Unicode strings with custom escape: U&'d!0061t!+000061' UESCAPE '!'
    • Dollar-quoted strings
      • just dollars: $$foo bar$$
      • with tags: $SomeTag$Dianne's horse$SomeTag$
  • Blob literals
    • Bit strings: B'1001 or b'0110'
    • Hex strings: X'1FA' or x'1FA'
  • Number literals (Postgres >= 16)
    • hex literals: 0xFFFF
    • oct literals: 0o666
    • bin literals: 0b0110
    • underscores in number literals: 10_000_000, 0xFFFF_FFFF, 1.618_034
  • Array literals: ARRAY[1,2,3]
    • probably need a bit of refactor in how we represent it in CST
  • Array constructors: ARRAY( SELECT ... )
  • Interval literals: INTERVAL '1 year 3 hours'
  • Date/Time literals: TIMESTAMP '2000-01-01T10:30:15', DATE '1999-07-20', TIME '13:30:00'
  • JSON literals: JSON '{"key": "value"}'
  • JSONB literals: JSONB '{"key": "value"}'
  • Row constructors: ROW(1, 2.5, 'this is a test')
  • Parameters: $foo, $123

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions