@@ -454,6 +454,14 @@ export class ExecContext {
454
454
*/
455
455
hasBoolAsChar = false ;
456
456
457
+ /**
458
+ * 'get_attname' function accepts 3 arguments.
459
+ *
460
+ * In PostgreSQL 10 and below 'get_attname' accepted 2 arguments and
461
+ * worked same way as current with 'true' passed as 3rd argument.
462
+ */
463
+ hasGetAttname3 = true ;
464
+
457
465
constructor ( nodeVarRegistry : NodeVarRegistry , specialMemberRegistry : SpecialMemberRegistry ,
458
466
debug : dbg . IDebuggerFacade , hashTableTypes : HashTableTypes ) {
459
467
this . nodeVarRegistry = nodeVarRegistry ;
@@ -1907,15 +1915,46 @@ class ExprNodeVariable extends NodeVariable {
1907
1915
const evalResult = await this . evaluate ( getAttnameExpr ) ;
1908
1916
const useGetAttname = this . debug . extractBool ( { ...evalResult , value : evalResult . result } ) ;
1909
1917
if ( useGetAttname ) {
1910
- /* Call this with `true` last - do not throw error if no such attribute found */
1911
- const r = await this . evaluate ( `get_attname(${ rtePtr } ->relid, ${ varattno } , true)` ) ;
1912
- const attname = this . debug . extractString ( { ...r , value : r . result } ) ;
1913
- if ( attname !== null ) {
1914
- return attname ;
1915
- }
1916
-
1917
- if ( this . debug . isFailedVar ( r ) ) {
1918
- this . context . hasGetAttname = false ;
1918
+ let r ;
1919
+ let attname ;
1920
+ if ( this . context . hasGetAttname3 ) {
1921
+ /*
1922
+ * There are 2 notes:
1923
+ *
1924
+ * 1. In older versions `get_attname` accepted only 2
1925
+ * arguments and behaved in same way as `true` is
1926
+ * passed today
1927
+ * 2. We first should check for failed var, not extract
1928
+ * string and check for null. My current code for
1929
+ * extracting strings is dumb and does not check for
1930
+ * such situations (so it will return non-null in
1931
+ * case of such error)
1932
+ */
1933
+ r = await this . evaluate ( `get_attname(${ rtePtr } ->relid, ${ varattno } , true)` ) ;
1934
+ if ( this . debug . isFailedVar ( r ) ) {
1935
+ if ( r . result . indexOf ( 'no matching function' ) !== - 1 ) {
1936
+ r = await this . evaluate ( `get_attname(${ rtePtr } ->relid, ${ varattno } )` ) ;
1937
+ if ( ! this . debug . isFailedVar ( r ) &&
1938
+ ( attname = this . debug . extractString ( { ...r , value : r . result } ) ) !== null ) {
1939
+ this . context . hasGetAttname3 = false ;
1940
+ return attname ;
1941
+ }
1942
+ } else {
1943
+ this . context . hasGetAttname = false ;
1944
+ }
1945
+ } else {
1946
+ attname = this . debug . extractString ( { ...r , value : r . result } ) ;
1947
+ if ( ! this . debug . isFailedVar ( r ) &&
1948
+ ( attname = this . debug . extractString ( { ...r , value : r . result } ) ) !== null ) {
1949
+ return attname ;
1950
+ }
1951
+ }
1952
+ } else {
1953
+ r = await this . evaluate ( `get_attname(${ rtePtr } ->relid, ${ varattno } )` ) ;
1954
+ if ( ! this . debug . isFailedVar ( r ) &&
1955
+ ( attname = this . debug . extractString ( { ...r , value : r . result } ) ) !== null ) {
1956
+ return attname ;
1957
+ }
1919
1958
}
1920
1959
}
1921
1960
}
0 commit comments