Home >Backend Development >Golang >Why Does My PostgreSQL Query Return a 'syntax error at end of input'?
Understanding the "Syntax error at end of input" Error in PostgreSQL
In PostgreSQL, the error message "pq: F:"scan.l" M:"syntax error at end of input" S:"ERROR" C:"42601" P:"50" R:"scanner_yyerror" L:"993"" indicates a problem with the syntax of a SQL statement.
Cause:
The specific issue in this case is likely due to the parameter placeholder character used in the prepared statement.
MySQL uses ? as the parameter placeholder, while PostgreSQL uses $1, $2, etc. In the provided SQL statement:
db.Query(`SELECT COUNT(*) as N FROM email WHERE address = ?`, email)
the question mark (?) is being used as a placeholder for the email address. However, PostgreSQL doesn't recognize this syntax.
Solution:
To resolve this issue, simply replace the question mark with $1:
db.Query(`SELECT COUNT(*) as N FROM email WHERE address = `, email)
Recommendation:
To avoid such errors in the future, always use the correct parameter placeholder supported by your specific database system.
The above is the detailed content of Why Does My PostgreSQL Query Return a 'syntax error at end of input'?. For more information, please follow other related articles on the PHP Chinese website!