Error Syntax Error At End Of Input Sqlstate 42601
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 error syntax error at end of input postgresql of this site About Us Learn more about Stack Overflow the company
Syntax Error At End Of Input Redshift
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Syntax Error At The End Of Input C
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:
Psqlexception: Error: Syntax Error At End Of Input
Sign up ERROR: syntax error at end of input, Java - Postgres up vote 0 down vote favorite I have used the next SQL statement but it fails in PostgreSQL. sentencia.execute("INSERT INTO \"Registros\" (accion,num_tarjeta,valor,fecha_accion_ano,fecha_accion_mes,fecha_accion_dia) VALUES ('recarga','" + num_tarjeta + "','" + valor_recargar + "','" + Calendar.getInstance().get(Calendar.YEAR) + "','" + Calendar.getInstance().get(Calendar.MONTH) + "','" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "'"); with this error: ERROR: syntax error postgres 42601 at end of input What's the problem? Thanks java sql postgresql share|improve this question asked May 15 '14 at 14:06 user3554506 314 2 The main problem is that you're specifying a value directly in SQL. Don't do that. Use parameterized SQL instead, to separate the code from the data. Once you've fixed that, you'll see the syntax error much more easily... as well as not being vulnerable to SQL injection attacks. Additionally, you're calling Calendar.getInstance() multiple times, which means you could be using multiple different values. Imagine if you're executing this right at the end of the year... you could end up with the "old" year but the "new" month and day values. Ick. –Jon Skeet May 15 '14 at 14:10 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted You're missing a ) at the end of the statement and the table is surrounded with double quotes for no reason.. INSERT INTO Registros (accion,num_tarjeta,valor,fecha_accion_ano,fecha_accion_mes,fecha_accion_dia) VALUES ('recarga','','','','','')"); share|improve this answer answered May 15 '14 at 14:07 JasonSec 409311 True! :) thanks –user3554506 May 15 '14
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 company Business Learn more pq syntax error at or near about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users error 42601 syntax error at or near Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each syntax error at end of input java other. Join them; it only takes a minute: Sign up PostgreSQL - SQL state: 42601 syntax error up vote 0 down vote favorite 2 I would like to know how to use a dynamic query inside a function. http://stackoverflow.com/questions/23680629/error-syntax-error-at-end-of-input-java-postgres I've tried lots of ways, however, when I try to compile my function a message SQL 42601 is displayed. The code that I use: CREATE OR REPLACE FUNCTION prc_tst_bulk(sql text) RETURNS TABLE (name text, rowcount integer) AS $$ BEGIN WITH v_tb_person AS (return query execute sql) select name, count(*) from v_tb_person where nome like '%a%' group by name union select name, count(*) from v_tb_person where gender = 1 group by name; END $$ LANGUAGE plpgsql; Error message http://stackoverflow.com/questions/16291944/postgresql-sql-state-42601-syntax-error I receive: ERROR: syntax error at or near "return" LINE 5: WITH v_tb_person AS (return query execute sql) I tried using: WITH v_tb_person AS (execute sql) WITH v_tb_person AS (query execute) WITH v_tb_person AS (return query execute) What is wrong? How can I solve this problem? Its a question related to PostgreSQL equivalent of Oracle “bulk collect” database postgresql plpgsql bulkinsert dynamic-sql share|improve this question edited Apr 30 '13 at 5:34 Erwin Brandstetter 219k29354465 asked Apr 30 '13 at 4:00 Leandro 5126 This is clearly plpgsql syntax. What is the [Oracle] tag doing here? –Erwin Brandstetter Apr 30 '13 at 5:29 @ErwinBrandstetter Previous question was about translating PL/SQL to PL/PgSQL, so probably carried that over. I've removed the tag. –Craig Ringer Apr 30 '13 at 5:31 One thing that can be well worth trying is the documentation. A lot of effort goes into the PostgreSQL (and PL/PgSQL) documentation. In this case, you'll want to start with Dynamic statements in PL/PgSQL. –Craig Ringer Apr 30 '13 at 5:42 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Your function would work like this: CREATE OR REPLACE FUNCTION prc_tst_bulk(sql text) RETURNS TABLE (name text, rowcount integer) AS $$ BEGIN RETURN QUERY EXECUTE ' WITH v_tb_person AS (' || sql || $x$) SELECT name, count(*)::int FROM v_tb_person WHERE nome LIKE
Regional lists Associations User groups Project lists pgadmin-hackers pgadmin-support pgsql-jdbc pgsql-odbc pgsql-pkg-debian pgsql-pkg-yum psycopg Inactive lists IRC https://www.postgresql.org/message-id/CAPvh4w31szZNu1b9dEJPge22Tw81YHPfs7ThnHjxU=2K-0-BaA@mail.gmail.com Local User Groups Featured Users International Sites Propaganda Resources Weekly News JDBC syntax error at end of input From: Hans Vasquez-Gross