Psqlexception Error Syntax Error At Or Near $1
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the syntax error at or near $1 postgres company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Postgresql Syntax Error At Or Near $1
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million org.postgresql.util.psqlexception: error: syntax error at or near ")" hibernate programmers, just like you, helping each other. Join them; it only takes a minute: Sign up org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1” up vote 4 down vote favorite I am getting this PSQLException: org.postgresql.util.PSQLException:
Caused By: Org.postgresql.util.psqlexception: Error: Syntax Error At Or Near "-"
ERROR: syntax error at or near "$1" Position: 37 When I run the following code: ps = connection.prepareStatement("SELECT current_timestamp + INTERVAL ?;"); ps.setString(1, "30 minutes"); System.out.println(ps); rs = ps.executeQuery(); However, the println function displays this in the console: SELECT current_timestamp + INTERVAL '30 minutes' Anyone know what is wrong? The query in the console runs fine in pgAdmin so I know it isn't a syntax error. java postgresql jdbc share|improve this question edited Oct org postgresql util psqlexception error syntax error at or near user 10 '15 at 20:33 BalusC 685k21024842699 asked Oct 10 '15 at 20:32 Kevin Orriss 416617 Makes no difference, the semicolon is perfectly valid –Kevin Orriss Oct 10 '15 at 20:34 the query works for me, is this is the actual code or do you have any variable in place of "30 minutes" –silentprogrammer Oct 10 '15 at 20:41 This is the actual code... Are you running postgres? –Kevin Orriss Oct 10 '15 at 20:42 There is a bug with setting strings as an interval, I am sure of it... setString works for other strings and setInt works too... –Kevin Orriss Oct 10 '15 at 20:51 It seems to be postgresql bug –herry Oct 10 '15 at 20:58 | show 3 more comments 2 Answers 2 active oldest votes up vote 5 down vote accepted Although the syntax INTERVAL '30 minutes' is valid when you write SQL directly in a console, it is actually considered to be an interval literal and won't work where the string that follows the word INTERVAL is not a literal string. Prepared statements in PostgreSQL are implemented on the server side using PREPARE and each ? is seen as an actual variable on the server. This is also why it complains about $1 a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
Pq Syntax Error At Or Near $1
Stack Overflow the company Business Learn more about hiring developers or posting ads with
Sql Error: 0, Sqlstate: 42601
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up syntax error at or near $1 and also some exception sql grammar exception up vote http://stackoverflow.com/questions/33058684/org-postgresql-util-psqlexception-error-syntax-error-at-or-near-1 0 down vote favorite I'm getting an error syntax error at or near $1 and also some exception sql grammar exception "select t1.* from ( select * from employee_additional_attributes where stwid in :stwIdList )" + "as t1 join ( select stwid, max(employee_additional_attribute_id) as employee_additional_attribute_id from employee_additional_attributes" + "where stwid in :stwIdList and mis_attribute_id in (:attributeId) and start_time <= date(:date) group by stwid )" + "as t2 using ( stwid, employee_additional_attribute_id" http://stackoverflow.com/questions/27922748/syntax-error-at-or-near-1-and-also-some-exception-sql-grammar-exception ) sql hibernate postgresql share|improve this question edited Jan 13 '15 at 13:32 a_horse_with_no_name 187k24237314 asked Jan 13 '15 at 12:56 Ramesh Kumar 14 can you add the exceptions to your question please –Matt Jan 13 '15 at 12:58 Please add the whole exceptions. –Jens Jan 13 '15 at 13:28 Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1" –Ramesh Kumar Jan 13 '15 at 13:33 Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet –Ramesh Kumar Jan 13 '15 at 13:34 @RameshKumar, update your question and add complete java exception stacktrace –Chaitanya Jan 13 '15 at 13:35 | show 1 more comment 1 Answer 1 active oldest votes up vote 0 down vote PostgreSQL use the $
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any http://dba.stackexchange.com/questions/103980/syntax-error-using-preparedstatements-with-postgresql questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for syntax error database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Syntax error using preparedstatements with syntax error at postgresql up vote 1 down vote favorite I have a Java application connecting to a PostgreSQL database. Using straightforward code like: ps = con.prepareStatement(sql); if (dataTypes != null && dataTypes.size() > 0) { for (int i = 0; i < dataTypes.size(); ++i) { if (dataTypes.get(i) == DataTypes.NUMERIC) ps.setLong((i + 1), Long.parseLong(values.get(i))); else ps.setString((i + 1), values.get(i)); } } rs = ps.executeQuery(); and with a query like select ? from dummy it just works fine. In the postgres logs what shows is: 2015-06-13 12:48:30 EEST [28294-3] xx LOG: execute