开发者社区> 问答> 正文

Druid 配置了SQL合并后,在查询PostgreSQL 主键ID是报错?报错

@wenshao 你好,想跟你请教个问题:

连接池配置

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />

		<property name="filters" value="stat" />
	        <property name="connectionProperties" value="druid.stat.mergeSql=true"/>

                <property name="maxActive" value="20" />
		<property name="initialSize" value="1" />
		<property name="maxWait" value="60000" />
		<property name="minIdle" value="1" />

		<property name="timeBetweenEvictionRunsMillis" value="3000" />
		<property name="minEvictableIdleTimeMillis" value="300000" />

		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />

		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

	</bean>
如果配置        <property name="connectionProperties" value="druid.stat.mergeSql=true" />

这条的话,就会报这个错

03:15:10,196 ERROR StatFilter:147 - merge sql error, dbType postgresql, sql : 
SELECT nextval('passport_id_seq'::regclass) as id
com.alibaba.druid.sql.parser.SQLParseException: syntax error, expect RPAREN, actual VARIANT :
	at com.alibaba.druid.sql.parser.SQLExprParser.accept(SQLExprParser.java:1204)
	at com.alibaba.druid.sql.parser.SQLExprParser.methodRest(SQLExprParser.java:534)
	at com.alibaba.druid.sql.parser.SQLExprParser.primaryRest(SQLExprParser.java:499)
	at com.alibaba.druid.sql.parser.SQLSelectParser.parseSelectList(SQLSelectParser.java:257)
	at com.alibaba.druid.sql.dialect.postgresql.parser.PGSelectParser.query(PGSelectParser.java:79)
	at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:59)
	at com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser.parseSelect(PGSQLStatementParser.java:316)
	at com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser.parseSelect(PGSQLStatementParser.java:40)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:86)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:70)
	at com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:41)
	at com.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)
	at com.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:627)
	at com.alibaba.druid.filter.stat.StatFilter.statementPrepareAfter(StatFilter.java:305)
	at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:124)
	at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:446)
	at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)
	at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:321)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:72)
	at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:82)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:54)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:70)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
	at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:65)
	at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processBefore(SelectKeyGenerator.java:41)
	at org.apache.ibatis.executor.statement.BaseStatementHandler.generateKeys(BaseStatementHandler.java:127)
	at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:60)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:36)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:42)
	at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:436)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:43)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
	at com.sun.proxy.$Proxy17.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:236)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:46)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
去掉那句话,就不问题


展开
收起
爱吃鱼的程序员 2020-06-22 20:42:17 897 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    快照版本这里:http://code.alibabatech.com/mvn/snapshots/com/alibaba/druid/0.2.16-SNAPSHOT

    我测试过,问题已经解决了。正式版本下个星期发布。

    十分感谢!这是postgres-styletypecast表达式,你提问之后,我查文档才懂。下个星期发布版本解决此问题。 createtableTUSER(IDvarchar(36)notnull,CREATEDATETIMEdatetime,MODIFYDATETIMEdatetime,NAMEvarchar(100)notnull,PWDvarchar(32)notnull,primarykey(ID))com.alibaba.druid.sql.parser.ParserException:TODOatcom.alibaba.druid.sql.parser.SQLExprParser.parsePrimaryKey(SQLExprParser.java:1298)atcom.alibaba.druid.sql.parser.SQLCreateTableParser.parseCrateTable(SQLCreateTableParser.java:75)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseCreate(SQLStatementParser.java:556)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:102)atcom.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:76)atcom.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:42)atcom.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)atcom.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:629)atcom.alibaba.druid.filter.stat.StatFilter.internalBeforeStatementExecute(StatFilter.java:397)atcom.alibaba.druid.filter.stat.StatFilter.statementExecuteUpdateBefore(StatFilter.java:325)atcom.alibaba.druid.filter.FilterEventAdapter.statement_executeUpdate(FilterEventAdapter.java:324)atcom.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2373)atcom.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeUpdate(StatementProxyImpl.java:225)atcom.alibaba.druid.pool.DruidPooledStatement.executeUpdate(DruidPooledStatement.java:169)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:227)atorg.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)atorg.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:505)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)atorg.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:591)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)atorg.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)atjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)atjava.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)atjava.util.concurrent.FutureTask.run(FutureTask.java:138)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)atjava.lang.Thread.run(Thread.java:619)

    sqlserver也报错啊


    2020-06-22 20:42:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
金融级 PostgreSQL监控及优化 立即下载
PostgreSQL在哈啰的实践-周飞 立即下载
PostgreSQL高并发数据库应用数据 立即下载

相关镜像