Org.postgresql.util.PSQLException: Field index exceeds license range: 3, Number of columns: 2.
Today, after writing the SQL query, the background has been error display the above information. Looking at the error for no reason at all, we re-examined the SQL and found that I added quotation marks to the outside of one of the receiving parameters while others did not add.
If the suspicion is caused by this, delete the quotation mark and execute again, there is no recurrence of the problem; look at the rest of the information, say yes. #{parentid} transposition ${parentid}, so it was tested in the case of quotation marks, the # will not be reported to the error. So I looked for a little bit about the difference between # and $ in sql:
1. # When the incoming data is treated as a string, a double quotation mark is added to the automatically passed data such as: SELECT * from User where parentid = #{parentid} When the value of ParentID is 100
SQL resolves to select * from User where parentid = "100"
2. $ The incoming data is displayed directly in the SQL statement such as: SELECT * from User where parentid = ${parentid} When the value of ParentID is 100
SQL resolves to select * from User where parentid = 100
The main difference is that: why do I need to use $ instead of # when I add quotes to my program?
Other than that:
1. #方式能够很大程度上防止sql注入, and $ cannot prevent SQL injection;
2. $ is typically used for incoming database objects, such as incoming table names;
3. MyBatis sort when using the order by dynamic parameter when using $ instead of #;
In short, you can use # when you don't need $ this is good;
Org.postgresql.util.PSQLException: Field index exceeds license range: 3, Number of columns: 2.