Yields default values for a function, given the string provided by pg_get_expr(pg_catalog.pg_proc.proargdefaults, 0)
(defaults_string)
| 27 | |
| 28 | |
| 29 | def parse_defaults(defaults_string): |
| 30 | """Yields default values for a function, given the string provided by |
| 31 | pg_get_expr(pg_catalog.pg_proc.proargdefaults, 0)""" |
| 32 | if not defaults_string: |
| 33 | return |
| 34 | current = "" |
| 35 | in_quote = None |
| 36 | for char in defaults_string: |
| 37 | if current == "" and char == " ": |
| 38 | # Skip space after comma separating default expressions |
| 39 | continue |
| 40 | if char == '"' or char == "'": |
| 41 | if in_quote and char == in_quote: |
| 42 | # End quote |
| 43 | in_quote = None |
| 44 | elif not in_quote: |
| 45 | # Begin quote |
| 46 | in_quote = char |
| 47 | elif char == "," and not in_quote: |
| 48 | # End of expression |
| 49 | yield current |
| 50 | current = "" |
| 51 | continue |
| 52 | current += char |
| 53 | yield current |
| 54 | |
| 55 | |
| 56 | class FunctionMetadata: |