pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unable to create triggers via jdbc. Tried so many anythings. Please help.
4+ messages / 4 participants
[nested] [flat]

* Unable to create triggers via jdbc. Tried so many anythings. Please help.
@ 2014-06-16 04:41 Coffee GoesToSchool <coffeegoestoschool@gmail.com>
  2014-06-16 13:15 ` Re: Unable to create triggers via jdbc. Tried so many anythings. Please help. Dave Cramer <pg@fastcrypt.com>
  2014-06-16 15:11 ` Re: Unable to create triggers via jdbc. Tried so many anythings. Please help. Hannes Erven <hannes@erven.at>
  0 siblings, 2 replies; 4+ messages in thread

From: Coffee GoesToSchool @ 2014-06-16 04:41 UTC (permalink / raw)
  To: pgsql-jdbc

Hi

I am unable to create functions via postgres jdbc. It seems that the driver
strips out newlines and semi-colons, resulting in syntax errors rejected by
the db.  I'm trying to setup dbdeploy for the project I'm working on. All
db artifacts (tables, sequence, views) are successfully managed except for
triggers.

db version:     postgres (PostgreSQL) 9.3.4
jdbc version:  org.postgresql:postgresql:9.3-1100-jdbc41
platform:        OS X 10.9.3

*Error in postgres log:*
ERROR:  syntax error at or near "$" at character 89
STATEMENT:    CREATE FUNCTION trigger_update_dates() RETURNS trigger
LANGUAGE plpgsql AS $ BEGIN IF TG_OP = 'INSERT' THEN NEW.CREATE_DATE :=
LOCALTIMESTAMP

*Stacktrace**:*
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or
near "$"
  Position: 89
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395)
at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:773)
at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:743)
at
org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1053)
at
org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:983)
at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:651)

*Trigger:*
CREATE FUNCTION trigger_update_dates() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
NEW.CREATE_DATE := LOCALTIMESTAMP;
NEW.UPDATE_DATE := LOCALTIMESTAMP;
END IF;
IF TG_OP = 'UPDATE' THEN
NEW.UPDATE_DATE := LOCALTIMESTAMP;
END IF;
RETURN NEW;
END
$$;


---CoffeeGoesToSchool

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

stacktrace.txt (text/plain, 7.1K) download * What went wrong: Execution failed for task ':installTriggers'. > org.postgresql.util.PSQLException: ERROR: syntax error at or near "$" Position: 89 * Try: Run with --debug option to get more log output. * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':installTriggers'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86) at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) at org.gradle.launcher.Main.doAction(Main.java:46) at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) at org.gradle.launcher.Main.main(Main.java:37) at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) at org.gradle.launcher.GradleMain.main(GradleMain.java:23) at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:55) Caused by: : org.postgresql.util.PSQLException: ERROR: syntax error at or near "$" Position: 89 at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:670) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:71) at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:86) at org.gradle.api.internal.project.DefaultAntBuilder.super$3$invokeMethod(DefaultAntBuilder.groovy) at org.gradle.api.internal.project.DefaultAntBuilder.invokeMethod(DefaultAntBuilder.groovy:37) at build_5eassra7ibpicbiroq5vog4p59$_run_closure6.doCall(/Users/kgoh/Development/kbSandbox/braveNewWorld/build.gradle:80) at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:502) at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:483) at org.gradle.api.internal.tasks.TaskStatusNagger$1.execute(TaskStatusNagger.java:77) at org.gradle.api.internal.tasks.TaskStatusNagger$1.execute(TaskStatusNagger.java:73) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) ... 46 more Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$" Position: 89 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395) at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:773) at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:743) at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1053) at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:983) at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:651) ... 59 more
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Unable to create triggers via jdbc. Tried so many anythings. Please help.
  2014-06-16 04:41 Unable to create triggers via jdbc. Tried so many anythings. Please help. Coffee GoesToSchool <coffeegoestoschool@gmail.com>
@ 2014-06-16 13:15 ` Dave Cramer <pg@fastcrypt.com>
  2014-06-16 14:49   ` Re: Unable to create triggers via jdbc. Tried so many anythings. Please help. Herouth Maoz <herouth@unicell.co.il>
  1 sibling, 1 reply; 4+ messages in thread

From: Dave Cramer @ 2014-06-16 13:15 UTC (permalink / raw)
  To: Coffee GoesToSchool <coffeegoestoschool@gmail.com>; +Cc: pgsql-jdbc

You can have a look here

http://stackoverflow.com/questions/10460542/create-postgresql-trigger-using-jdbc

I suspect the parser is trying to parse the $$ but it appears you aren't
the first to try to solve this problem

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On 16 June 2014 00:41, Coffee GoesToSchool <coffeegoestoschool@gmail.com>
wrote:

>
> Hi
>
> I am unable to create functions via postgres jdbc. It seems that the
> driver strips out newlines and semi-colons, resulting in syntax errors
> rejected by the db.  I'm trying to setup dbdeploy for the project I'm
> working on. All db artifacts (tables, sequence, views) are successfully
> managed except for triggers.
>
> db version:     postgres (PostgreSQL) 9.3.4
> jdbc version:  org.postgresql:postgresql:9.3-1100-jdbc41
> platform:        OS X 10.9.3
>
> *Error in postgres log:*
> ERROR:  syntax error at or near "$" at character 89
> STATEMENT:    CREATE FUNCTION trigger_update_dates() RETURNS trigger
> LANGUAGE plpgsql AS $ BEGIN IF TG_OP = 'INSERT' THEN NEW.CREATE_DATE :=
> LOCALTIMESTAMP
>
> *Stacktrace**:*
> Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or
> near "$"
>   Position: 89
> at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
>  at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
>  at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
>  at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395)
> at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:773)
>  at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:743)
> at
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1053)
>  at
> org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:983)
> at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:651)
>
> *Trigger:*
> CREATE FUNCTION trigger_update_dates() RETURNS trigger
>     LANGUAGE plpgsql
>     AS $$
> BEGIN
> IF TG_OP = 'INSERT' THEN
>  NEW.CREATE_DATE := LOCALTIMESTAMP;
> NEW.UPDATE_DATE := LOCALTIMESTAMP;
> END IF;
>  IF TG_OP = 'UPDATE' THEN
> NEW.UPDATE_DATE := LOCALTIMESTAMP;
> END IF;
> RETURN NEW;
> END
> $$;
>
>
> ---CoffeeGoesToSchool
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Unable to create triggers via jdbc. Tried so many anythings. Please help.
  2014-06-16 04:41 Unable to create triggers via jdbc. Tried so many anythings. Please help. Coffee GoesToSchool <coffeegoestoschool@gmail.com>
  2014-06-16 13:15 ` Re: Unable to create triggers via jdbc. Tried so many anythings. Please help. Dave Cramer <pg@fastcrypt.com>
@ 2014-06-16 14:49   ` Herouth Maoz <herouth@unicell.co.il>
  0 siblings, 0 replies; 4+ messages in thread

From: Herouth Maoz @ 2014-06-16 14:49 UTC (permalink / raw)
  To: pgsql-jdbc

If the problem is with the $ quoting, you can use plain quoting. After 
all, the main reason for using $ quoting is to avoid the need to escape 
all the quotation marks within the function body. And JDBC can do that 
for you if you use a prepared statement.

I would try using a "full" $ quoting first, that is, instead of $$ use 
$func$ or something like that. But if that fails, use a prepared 
statement just with

CREATE FUNCTION trigger_update_dates() RETURNS trigger LANGUAGE plpgsql AS ?

And then use setString() to add the body of the function, and execute() 
the statement.

áúàøéê 16/06/14, 16:15, öéèåè Dave Cramer:
> You can have a look here
>
> http://stackoverflow.com/questions/10460542/create-postgresql-trigger-using-jdbc
>
> I suspect the parser is trying to parse the $$ but it appears you 
> aren't the first to try to solve this problem
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On 16 June 2014 00:41, Coffee GoesToSchool 
> <coffeegoestoschool@gmail.com <mailto:coffeegoestoschool@gmail.com>> 
> wrote:
>
>
>     Hi
>
>     I am unable to create functions via postgres jdbc. It seems that
>     the driver strips out newlines and semi-colons, resulting in
>     syntax errors rejected by the db.  I'm trying to setup dbdeploy
>     for the project I'm working on. All db artifacts (tables,
>     sequence, views) are successfully managed except for triggers.
>
>     db version:     postgres (PostgreSQL) 9.3.4
>     jdbc version:  org.postgresql:postgresql:9.3-1100-jdbc41
>     platform:        OS X 10.9.3
>
>     *Error in postgres log:*
>     ERROR:  syntax error at or near "$" at character 89
>     STATEMENT:    CREATE FUNCTION trigger_update_dates() RETURNS
>     trigger LANGUAGE plpgsql AS $ BEGIN IF TG_OP = 'INSERT' THEN
>     NEW.CREATE_DATE := LOCALTIMESTAMP
>
>     *Stacktrace**:*
>     Caused by: org.postgresql.util.PSQLException: ERROR: syntax error
>     at or near "$"
>       Position: 89
>     at
>     org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
>     at
>     org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
>     at
>     org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
>     at
>     org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
>     at
>     org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
>     at
>     org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395)
>     at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:773)
>     at
>     org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:743)
>     at
>     org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1053)
>     at
>     org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:983)
>     at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:651)
>
>     *Trigger:*
>     CREATE FUNCTION trigger_update_dates() RETURNS trigger
>         LANGUAGE plpgsql
>         AS $$
>     BEGIN
>     IF TG_OP = 'INSERT' THEN
>     NEW.CREATE_DATE := LOCALTIMESTAMP;
>     NEW.UPDATE_DATE := LOCALTIMESTAMP;
>     END IF;
>     IF TG_OP = 'UPDATE' THEN
>     NEW.UPDATE_DATE := LOCALTIMESTAMP;
>     END IF;
>     RETURN NEW;
>     END
>     $$;
>
>
>     ---CoffeeGoesToSchool
>
>
>     --
>     Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org
>     <mailto:pgsql-jdbc@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-jdbc
>
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Unable to create triggers via jdbc. Tried so many anythings. Please help.
  2014-06-16 04:41 Unable to create triggers via jdbc. Tried so many anythings. Please help. Coffee GoesToSchool <coffeegoestoschool@gmail.com>
@ 2014-06-16 15:11 ` Hannes Erven <hannes@erven.at>
  1 sibling, 0 replies; 4+ messages in thread

From: Hannes Erven @ 2014-06-16 15:11 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,


 > I am unable to create functions via postgres jdbc. It seems that the
 > driver strips out newlines and semi-colons, resulting in syntax
 > errors rejected by the db.

Since this appears to be an ANT task and $ has a special meaning for it, 
have you tried setting "expandproperties" to "false"?
http://ant.apache.org/manual/Tasks/sql.html

Maybe there is also some other way to tell ANT to treat that $$ signs as 
verbatim (perhaps 
http://stackoverflow.com/questions/2631082/escaping-a-dollar-in-the-middle-of-an-ant-property 
).


-hannes


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2014-06-16 15:11 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-06-16 04:41 Unable to create triggers via jdbc. Tried so many anythings. Please help. Coffee GoesToSchool <coffeegoestoschool@gmail.com>
2014-06-16 13:15 ` Dave Cramer <pg@fastcrypt.com>
2014-06-16 14:49   ` Herouth Maoz <herouth@unicell.co.il>
2014-06-16 15:11 ` Hannes Erven <hannes@erven.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox