- Notifications
You must be signed in to change notification settings - Fork28
Commite984ef5
committed
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The controlstructure feature per se is complete, but the boolean expressionsunderstood by \if and \elif are pretty primitive; basically, aftervariable substitution and backtick expansion, the result has to be"true" or "false" or one of the other standard spellings of a booleanvalue. But that's enough for many purposes, since you can alwaysdo the heavy lifting on the server side; and we can extend it later.Along the way, pay down some of the technical debt that had built uparound psql/command.c:* Refactor exec_command() into a function per command, instead ofbeing a 1500-line monstrosity. This makes the file noticeably longerbecause of repetitive function header/trailer overhead, but it seemsmuch more readable.* Teach psql_get_variable() and psqlscanslash.l to suppress variablesubstitution and backtick expansion on the basis of the conditionalstack state, thereby allowing removal of the OT_NO_EVAL kluge.* Fix the no-doubt-once-expedient hack of sometimes silently substitutingmainloop.c's previous_buf for query_buf when calling HandleSlashCmds.(It's a bit remarkable that commands like \r worked at all with that.)Recall of a previous query is now done explicitly in the slash commandswhere that should happen.Corey Huinker, reviewed by Fabien Coelho, further hacking by meDiscussion:https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com1 parentffae673 commite984ef5
File tree
17 files changed
+2172
-270
lines changed- doc/src/sgml/ref
- src
- bin/psql
- test/regress
- expected
- sql
17 files changed
+2172
-270
lines changedLines changed: 91 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2063 | 2063 |
| |
2064 | 2064 |
| |
2065 | 2065 |
| |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
2066 | 2155 |
| |
2067 | 2156 |
| |
2068 | 2157 |
| |
| |||
3715 | 3804 |
| |
3716 | 3805 |
| |
3717 | 3806 |
| |
3718 |
| - | |
| 3807 | + | |
| 3808 | + | |
3719 | 3809 |
| |
3720 | 3810 |
| |
3721 | 3811 |
| |
|
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
24 |
| - | |
25 |
| - | |
26 |
| - | |
27 |
| - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
|
0 commit comments
Comments
(0)