how insert custom column with mybatis in pgsql - mybatis

my code like this
<select id = "getVideoOrgTreeChannels" resultMap="orgTreeChannels">
select so.id id, so.company_name, so.company_code,
${sysCode} as sysCode,
${plateNo} as plateNo
from sys_organization so
where so.id=#{companyId}
and so.company_status='0'
</select>
and the mybatis can not generate prepare sql。The error log like this
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#2a7ed399] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl#700c3c28] will not be managed by Spring
==> Preparing: select so.id id, so.company_name, so.company_code, as sysCode, as plateNo from sys_organization so where so.id=? and so.company_status='0'
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#2a7ed399]
2023-01-31 15:59:20.549 [http-nio-8081-exec-4] ERROR c.g.boot.common.exception.GciBootExceptionHandler:55 -
### Error querying database. Cause: java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 62, line 1, column 51, token AS : select so.id id, so.company_name, so.company_code,
as sysCode,
as plateNo
from sys_organization so
where so.id=?
and so.company_status='0'
### The error may exist in file [D:\workProject\gci_video_3\webSite\src\gci-video-web-service\gci-video-web\gci-boot-video-manage\target\classes\com\gci\boot\modules\video\mapper\xml\VideoBusinessDataMapper.xml]
### The error may involve com.gci.boot.modules.video.mapper.VideoBusinessDataMapper.getVideoOrgTreeChannels
### The error occurred while executing a query
### SQL: select so.id id, so.company_name, so.company_code, as sysCode, as plateNo from sys_organization so where so.id=? and so.company_status='0'
### Cause: java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 62, line 1, column 51, token AS : select so.id id, so.company_name, so.company_code,
as sysCode,
as plateNo
from sys_organization so
where so.id=?
and so.company_status='0'
; uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error: ERROR. pos 62, line 1, column 51, token AS : select so.id id, so.company_name, so.company_code,
as sysCode,
as plateNo
from sys_organization so
where so.id=?
and so.company_status='0'; nested exception is java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 62, line 1, column 51, token AS : select so.id id, so.company_name, so.company_code,
as sysCode,
as plateNo
from sys_organization so
where so.id=?
and so.company_status='0'
when I execute sql statement. it can insert column and my sql statement like this
select so.id as isd, so.company_name, so.company_code ,'syscode' as title from sys_organization so;
it can insert custom column successfully.
isd |company_name|company_code|title |
-------------------+------------+------------+-------+
1613079881513832449|测试公司 |A01 |syscode|
1613079972102410241|开发一部 |A01A01 |syscode|
1613080029140750337|开发二部 |A01A02 |syscode|
1613080075039019009|交通开发公司 |A02 |syscode|
1613089530539556865|技术一部 |A02A01 |syscode|
1613089567768199170|技术二部 |A02A02 |syscode|
1613089659170471937|技术三部 |A02A03 |syscode|

Related

Generate missing non-contiguous date ranges

I have the following example dataset (actual table is about 30000 rows).
I need to scan through the table and identify any non-contiguous dates for all references within the table that have non-contiguous data, and generate data to fill in the missing dates
So for the above reference I would need example data generated to be in bold below (showing existing rows for clarity):
ID
START_DATE
END_DATE
7172
2020-03-13
2020-10-22
7172
2020-10-23
2020-11-08
7172
2020-11-09
2020-11-09
7172
2020-11-10
2020-11-19
7172
2020-11-20
2020-11-20
7172
2020-11-21
2021-03-14
7172
2021-03-15
2021-03-17
7172
2021-03-18
2021-03-19
7172
2021-03-20
2021-03-28
7172
2021-03-29
2021-04-25
7172
2021-04-26
2021-30-04
7172
2021-05-01
2021-06-07
7172
2021-06-08
2021-06-08
7172
2021-06-09
2022-01-09
Can anyone help please?
You can make life a bit easier on respondents by making "Readily Consumable" Test Data, like the following example... (I added in the extra ID that #PatrickHurst did)...
--===== Create and populate the test table with the given test data.
-- This is NOT a part of the solution.
DROP TABLE IF EXISTS #Test;
GO
CREATE TABLE #Test
(
ID INT
, START_DATE DATE
, END_DATE DATE
)
;
INSERT INTO #Test (ID, START_DATE, END_DATE) VALUES
(7172,'2020-03-13','2020-10-22')
,(7172,'2020-10-23','2020-11-08')
--,(7172,'2020-11-09','2020-11-09') --Is Missing
,(7172,'2020-11-10','2020-11-19')
--,(7172,'2020-11-20','2020-11-20') --Is Missing
,(7172,'2020-11-21','2021-03-14')
,(7172,'2021-03-15','2021-03-17')
--,(7172,'2021-03-18','2021-03-19') --Is Missing
,(7172,'2021-03-20','2021-03-28')
,(7172,'2021-03-29','2021-04-25')
--,(7172,'2021-04-26','2021-04-30') --Is Missing (And you had a bad date here)
,(7172,'2021-05-01','2021-06-07')
--,(7172,'2021-06-08','2021-06-08') --Is Missing
,(7172,'2021-06-09','2022-01-09')
,(1234,'2020-03-13','2022-03-15')
,(1234,'2022-03-20','2022-03-25')
;
If you have SQL Server 2012 or above, LAG makes this easy (and someone can probably simplify it even more)...
WITH cte AS
(
SELECT *
,mSTART_DATE = LAG(DATEADD(dd,1,END_DATE),1,START_DATE) OVER (PARTITION BY ID ORDER BY START_DATE)
,mEND_DATE = DATEADD(dd,-1,START_DATE)
FROM #Test
)
--===== Finds the existing date ranges
SELECT ID, START_DATE, END_DATE, Comment = '' FROM #Test
UNION ALL
--===== Finds the missing date ranges
SELECT ID,mSTART_DATE,mEND_DATE, Comment = 'Was Missing' FROM cte WHERE mSTART_DATE <> START_DATE
ORDER BY ID, START_DATE
;
Here are the results...
If you truly only want the missing date ranges, then the following does it...
WITH cte AS
(
SELECT *
,mSTART_DATE = LAG(DATEADD(dd,1,END_DATE),1,START_DATE) OVER (PARTITION BY ID ORDER BY START_DATE)
,mEND_DATE = DATEADD(dd,-1,START_DATE)
FROM #Test
)
SELECT ID,START_DATE = mSTART_DATE,END_DATE = mEND_DATE FROM cte WHERE mSTART_DATE <> START_DATE
ORDER BY ID,START_DATE
;
Results:
2021-30-04 is a bad date (hehe).
I took your table and used it to generate a table variable, and added a couple of rows:
DECLARE #TABLE TABLE (ID INT, START_DATE DATE, END_DATE DATE)
INSERT INTO #TABLE (ID, START_DATE, END_DATE) VALUES
(7172, '2020-03-13', '2020-10-22'), (7172, '2020-10-23', '2020-11-08'),
(7172, '2020-11-10', '2020-11-19'), (7172, '2020-11-20', '2020-11-20'),
(7172, '2020-11-21', '2021-03-14'), (7172, '2021-03-15', '2021-03-17'),
(7172, '2021-03-20', '2021-03-28'), (7172, '2021-03-29', '2021-04-25'),
(7172, '2021-05-01', '2021-06-07'), (7172, '2021-06-09', '2022-01-09'),
(1234, '2020-03-13', '2022-03-15'), (1234, '2022-03-20', '2022-03-25');
If I understand correctly, we'd be looking to generate rows:
--(7172, '2020-11-09', '2020-11-09'),
--(7172, '2021-03-18', '2021-03-19'),
--(7172, '2021-04-26', '2021-03-04'),
--(7172, '2021-06-08', '2021-06-08'),
--(1234, '2022-03-16', '2022-03-19'),
I poked at this some, and got the result you're looking for using some recursive CTE voodoo. I can't promise this is going to be performant, but it might be a good starting point:
DECLARE #MaxDate DATE = (SELECT MAX(END_DATE) FROM #TABLE)
;WITH DateRange AS (
SELECT ID, MIN(END_DATE) AS Date FROM #TABLE GROUP BY ID--#MinDate AS Date
UNION ALL
SELECT ID, DATEADD(DAY,1,Date)
FROM DateRange
WHERE Date < #MaxDate
), MissingDates AS (
SELECT dr.ID, dr.Date, t.START_DATE, t.END_DATE
FROM DateRange dr
LEFT OUTER JOIN #TABLE t
ON dr.Date BETWEEN t.START_DATE AND t.END_DATE
AND dr.ID = t.ID
WHERE t.ID IS NULL
), ranges AS (
SELECT s.ID, s.date AS START_DATE, s.date AS END_DATE, DATEADD(DAY,1,s.Date) AS NEXT_DATE
FROM MissingDates s
LEFT OUTER JOIN MissingDates n
ON s.Date = DATEADD(DAY,1,n.Date)
AND s.ID = n.ID
WHERE n.Date IS NULL
UNION ALL
SELECT a.ID, a.START_DATE, r.Date AS END_DATE, DATEADD(DAY,1,r.Date) AS NEXT_DATE
FROM ranges a
INNER JOIN MissingDates r
ON a.NEXT_DATE = r.Date
AND a.ID = r.ID
)
SELECT ID AS ID, START_DATE, MAX(END_DATE) AS END_DATE
FROM ranges
GROUP BY ID, START_DATE
OPTION (MAXRECURSION 0)
ID START_DATE END_DATE
----------------------------
7172 2020-11-09 2020-11-09
7172 2021-03-18 2021-03-19
7172 2021-04-26 2021-04-30
7172 2021-06-08 2021-06-08
7172 2022-01-10 2022-03-25
1234 2022-03-16 2022-03-19

Spring Batch: JdbcPagingItemReader does not work through setSortKeys and cast(id as unsigned)

I am working with Spring Batch version 3.0.7 with Mysql
I had the problem that the person_reader table has the id column defined how varchar and thus the following happens for a simple select ordered:
id
--
1
10 <--- !!!
2
3
...
What is need it is
id
--
1
2
3
...
10 <--- ok!
...
The solution is use ORDER BY cast(id as unsigned)
If I use JdbcCursorItemReader I can use in peace:
setSql("SELECT id, first_name, last_name FROM person_reader ORDER BY cast(id as unsigned)");
It works fine. Until here all is ok.
Note: for the batch process, is very important read the data in the correct order.
The problem is with JdbcPagingItemReader
First Try:
JdbcPagingItemReader<Person> itemReader = new JdbcPagingItemReader<>();
itemReader.setDataSource(dataSource);
itemReader.setPageSize(100);
itemReader.setRowMapper(new PersonRowMapper());
MySqlPagingQueryProvider pagingQueryProvider = new MySqlPagingQueryProvider();
pagingQueryProvider.setSelectClause("SELECT id, first_name, last_name");
pagingQueryProvider.setFromClause("FROM person_reader ORDER BY cast(id as unsigned)");
Map<String, Order> sortKeys= new HashMap<>();
sortKeys.put("id", Order.ASCENDING);
pagingQueryProvider.setSortKeys(sortKeys);
itemReader.setQueryProvider(pagingQueryProvider);
Observe:
setFromClause("FROM person_reader ORDER BY cast(id as unsigned)")
put("id", Order.ASCENDING)
The following error appears:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback;
bad SQL grammar [SELECT id, first_name, last_name FROM person_reader ORDER BY cast(id as unsigned) ORDER BY id ASC LIMIT 100];
nested exception is java.sql.SQLSyntaxErrorException:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id ASC LIMIT 100' at line 1
Has sense, the SQL generated SELECT id, first_name, last_name FROM person_reader ORDER BY cast(id as unsigned) ORDER BY id ASC LIMIT 100 is not correct.
Second Try
JdbcPagingItemReader<Person> itemReader = new JdbcPagingItemReader<>();
itemReader.setDataSource(dataSource);
itemReader.setPageSize(100);
itemReader.setRowMapper(new PersonRowMapper());
MySqlPagingQueryProvider pagingQueryProvider = new MySqlPagingQueryProvider();
pagingQueryProvider.setSelectClause("SELECT id, first_name, last_name");
pagingQueryProvider.setFromClause("FROM person_reader");
Map<String, Order> sortKeys= new HashMap<>();
sortKeys.put("cast(id as unsigned)", Order.ASCENDING);
pagingQueryProvider.setSortKeys(sortKeys);
itemReader.setQueryProvider(pagingQueryProvider);
Observe:
setFromClause("FROM person_reader")
put("cast(id as unsigned)", Order.ASCENDING)
The following error appears:
org.springframework.jdbc.UncategorizedSQLException: StatementCallback;
uncategorized SQLException for SQL [SELECT id, first_name, last_name FROM person_reader ORDER BY cast(id as unsigned) ASC LIMIT 100];
SQL state [S0022]; error code [0]; Column 'cast(id as unsigned)' not found.;
nested exception is java.sql.SQLException: Column 'cast(id as unsigned)' not found.
Has sense about the 'missing' column
Order is an enum and thus it can't be extended.
What is the correct approach?
Alpha
If I use in MySQL's workbench the following:
SELECT id, first_name, last_name, cast(id as unsigned) as sb_sort_column FROM person_reader ORDER BY sb_sort_column ASC
It works fine. If I use:
MySqlPagingQueryProvider pagingQueryProvider = new MySqlPagingQueryProvider();
pagingQueryProvider.setSelectClause("SELECT id, first_name, last_name, cast(id as unsigned) as sb_sort_column");
pagingQueryProvider.setFromClause("FROM person_reader");
Map<String, Order> sortKeys= new HashMap<>();
sortKeys.put("sb_sort_column", Order.ASCENDING);
pagingQueryProvider.setSortKeys(sortKeys);
itemReader.setQueryProvider(pagingQueryProvider);
The following error arises:
org.springframework.jdbc.BadSqlGrammarException:
PreparedStatementCallback;
bad SQL grammar [SELECT id, first_name, last_name, cast(id as unsigned) as sb_sort_column FROM person_reader WHERE ((sb_sort_column > ?)) ORDER BY sb_sort_column ASC LIMIT 100];
nested exception is java.sql.SQLSyntaxErrorException:
Unknown column 'sb_sort_column' in 'where clause'
From above see carefully the 3rd line about the sql statement generated.
Manuel's earlier answer will work, so removing the duplicate portion of mine...
Unfortunately, despite being functionally accurate, doing an ORDER BY on a function will probably run pretty poorly, since it will have to scan the entire table to do the cast, and I don't believe MySQL lets you create an index on function yet.
That said, as of MySQL 5.7.6, you could add a virtual column CAST(ID as UNSIGNED) as SORT_ID to the table and then index the virtual column.
Solution:
The link provided in the comment was useful.
It from:
Spring batch with column alias as sort key - malformed “where” statement
Therefore the correct configuration is:
MySqlPagingQueryProvider pagingQueryProvider = new MySqlPagingQueryProvider();
pagingQueryProvider.setSelectClause("SELECT id, first_name, last_name, sb_sort_column");
pagingQueryProvider.setFromClause("FROM (SELECT id, first_name, last_name, cast(id as unsigned) as sb_sort_column FROM person_reader) person_reader");
Map<String, Order> sortKeys= new HashMap<>();
sortKeys.put("sb_sort_column", Order.ASCENDING);
pagingQueryProvider.setSortKeys(sortKeys);
Note: be sure to include in the setSelectClause method the alias column, in this case sb_sort_column

Syntax error at or near "USING"

I am trying to recreate the functionality of a query found inside of a mapfile on our mapserver into a plpgsql stored procedure.
Here is the query:
geom from (select g.gid, g.geom, g.basin, a.\"DATE\", a.\"VALUE\" from sarffg_basins_00_regional_3sec as g join \"%prod_table%\" as a on g.basin = a.\"BASIN\" where a.\"DATE\" = '%prod_date%') as subquery using unique gid using srid=4326
Within my stored procedure, I have:
RETURN QUERY
EXECUTE 'SELECT geom FROM (
SELECT g.gid,
g.geom,
g.basin,
a.date,
a.value
FROM sarffg_basins_00_regional_3sec AS g
JOIN '||tablename_ts||' AS a
ON g.basin = a.basin
WHERE a.date = '''||adj_timestamp||''')
AS subquery USING UNIQUE gid USING srid=4326';
The above query found within my mapfile works fine. When I try calling my stored procedure inside of psql, I get:
ERROR: syntax error at or near "USING"
LINE 11: AS subquery USING UNIQUE gid USING srid=4326
^
QUERY: SELECT geom FROM (
SELECT g.gid,
g.geom,
g.basin,
a.date,
a.value
FROM sarffg_basins_00_regional_3sec AS g
JOIN temp_table_ts AS a
ON g.basin = a.basin
WHERE a.date = '2017-01-15 00:00:00+00')
AS subquery USING UNIQUE gid USING srid=4326
CONTEXT: PL/pgSQL function ingest_ffgs_prod_composite_csv(text,bigint,boolean,boolean) line 239 at RETURN QUERY
I have also tried omitting the "using" clause within my function and instead leaving that part within the mapfile after my stored procedure is called, i.e.:
DATA "select * from ingest_ffgs_prod_composite_csv('%prod_table%', 1484438400) as subquery using unique gid using srid=4326"
With the stored procedure containing:
RETURN QUERY
EXECUTE 'SELECT geom FROM (
SELECT g.gid,
g.geom,
g.basin,
a.date,
a.value
FROM sarffg_basins_00_regional_3sec AS g
JOIN '||tablename_ts||' AS a
ON g.basin = a.basin
WHERE a.date = '''||adj_timestamp||''');
But this leaves me with the error in my mapserver error log:
[Wed Jan 25 02:28:17 2017].593733 msDrawMap(): Image handling error. Failed to draw layer named 'regional_basin_values'.
[Wed Jan 25 02:28:17 2017].659656 msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR: syntax error at or near "select"
LINE 1: ..._BASIN_TIMESERIES', 1484438400) as subquery where select * &...
^
[Wed Jan 25 02:28:17 2017].659862 msDrawMap(): Image handling error. Failed to draw layer named 'regional_basin_product'.
[Wed Jan 25 02:28:22 2017].836950 msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR: syntax error at or near "select"
LINE 1: ..._BASIN_TIMESERIES', 1484438400) as subquery where select * &...
Finally, I tried leaving the front part of the query within the mapfile and only turning the subquery into the stored procedure:
mapfile:
DATA "geom from (select * from ingest_ffgs_prod_composite_csv('%prod_table%', 1484438400)) as subquery using unique gid using srid=4326"
stored procedure:
RETURN QUERY
EXECUTE 'SELECT g.gid,
g.geom,
g.basin,
a.date,
a.value
FROM sarffg_basins_00_regional_3sec AS g
JOIN '||tablename_ts||' AS a
ON g.basin = a.basin
WHERE a.date = '''||adj_timestamp||''');
And this leaves me with:
[Wed Jan 25 02:35:36 2017].527302 msDrawMap(): Image handling error. Failed to draw layer named 'regional_basin_values'.
[Wed Jan 25 02:35:36 2017].617289 msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR: column "VALUE" does not exist
LINE 1: select "VALUE",encode(ST_AsBinary(ST_Force2D("geom"),'NDR'),...
^
[Wed Jan 25 02:35:36 2017].617511 msDrawMap(): Image handling error. Failed to draw layer named 'regional_basin_product'.
[Wed Jan 25 02:35:42 2017].103566 msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR: column "VALUE" does not exist
LINE 1: select "VALUE",encode(ST_AsBinary(ST_Force2D("geom"),'NDR'),...
The return statement being executed here is:
RETURN QUERY
EXECUTE 'SELECT g.'||quote_ident('gid')||',
g.'||quote_ident('geom')||',
g.'||quote_ident('basin')||',
a.'||quote_ident('DATE')||',
a.'||quote_ident('VALUE')||'
FROM sarffg_basins_00_regional_3sec AS g JOIN '||quote_ident(prod_table)||' AS a
ON g.'||quote_ident('basin')||' = a.'||quote_ident('BASIN')||'
WHERE a.'||quote_ident('DATE')||' = '''||adj_timestamp||'''';
I have verified that prod_table has a column called "VALUE", so I'm not sure why I would be seeing this error. It is also important to note that calling my procedure from within psql yields no errors.
(I have two very similar return statements because my code queries a table with capital column names, and in the absence of that table it creates one from a CSV that doesn't have the capital names.)
Also not sure if it's relevant but here is what my function returns:
RETURNS table (
gid integer,
geom geometry(MultiPolygon,4326),
basin double precision,
date timestamptz,
value double precision
)
Any help would be greatly appreciated
I guess, you use the field VALUE in a filter or something similar in the mapfile (hard to say for sure without mapfile).
This filter must expect capitalized column names and this is why the original query had also capitalized column names:
select g.gid, g.geom, g.basin, a.\"DATE\", a.\"VALUE\" from....
If so, you only have to capitalize the columns returned by your procedure:
RETURNS table (
gid integer,
geom geometry(MultiPolygon,4326),
basin double precision,
"DATE" timestamptz,
"VALUE" double precision
)
Remember that in PostgreSql the case of column and table names matter if you surround then with double quote.
This query:
SELECT VALUE from ...
is case independent, while this one:
SELECT "VALUE" from ...
really requires a table with capitalized column names. And tables with capitalized column names require double quote:
CREATE TABLE test ("VALUE" text, .....

Intellij Idea Ultimate Postgres/EDB database plugin "oid" is ambigous

I use Intellij Idea Ultimate 2016.3 version. I try to connect to Postgres DB using the Intellij Idea's default "Database" plugin. However when i try to sync with the DB, I see this in the event log:
ERROR: column reference "oid" is ambiguous Position: 1205.
I tried checking the logs and this is what I found.
Caused by: org.jetbrains.dekaf.exceptions.StrippedSQLException: org.postgresql.util.PSQLException: ERROR: column reference "oid" is ambiguous Position: 1205
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:413)
at org.jetbrains.dekaf.jdbc.JdbcIntermediateSeance.execute(JdbcIntermediateSeance.java:100)
at com.intellij.database.remote.jdba.impl.RemoteSeanceImpl.execute(RemoteSeanceImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
... 3 more
Then I see there is a query like below getting executed.
The SQL statement:
select max(last_tx) as state_number from (select max(xmin::varchar::bigint) as last_tx
from pg_catalog.pg_type
where typnamespace = oid(?)
union all
select max(xmin::varchar::bigint) as last_tx
from pg_catalog.pg_class where relnamespace = oid(?)
union all
select max(xmin::varchar::bigint) as last_tx
from pg_catalog.pg_proc where pronamespace = oid(?)
union all
select max(xmin::varchar::bigint) as last_tx
from pg_catalog.pg_operator where oprnamespace = oid(?)
union all
select max(A.xmin::varchar::bigint) as last_tx
from pg_catalog.pg_attribute A
join pg_catalog.pg_class K on K.oid = A.attrelid
where K.relnamespace = oid(?)
union all
select max(xmin::varchar::bigint) as last_tx
from pg_catalog.pg_constraint
where connamespace = oid(?)
union all
select max(IX.xmin::varchar::bigint) as last_tx
from pg_catalog.pg_index IX, pg_catalog.pg_class IC
where IC.oid = IX.indrelid and IC.relnamespace = oid(?)
union all
select max(RU.xmin::varchar::bigint) as last_tx
from pg_catalog.pg_rewrite RU, pg_catalog.pg_class RC
where RC.oid = RU.ev_class and RC.relnamespace = oid(?)
union all
select max(TG.xmin::varchar::bigint) as last_tx
from pg_catalog.pg_trigger TG, pg_catalog.pg_class TC
where TC.oid = TG.tgrelid and TC.relnamespace = oid(?)
union all
select max(DE.xmin::varchar::bigint) as last_tx
from pg_catalog.pg_description DE, pg_catalog.pg_class DC
where DC.oid = DE.objoid and DC.relnamespace = oid(?) and DC.relkind in ('r', 'm', 'v')
)
After a thorough search on Intellij Idea forums, I did the following:
While creating the connection, under "Options" tab, provide a Object filter. Ex: table:ABC_.* (assuming all the tables start with a ABC_ prefix)
Check on "Introspect using JDBC metadata"
Choose "Except System Schemas" from the select box "Load sources for"
After the above steps, was able to resolve the issue. The below links helped me:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/207089995--Basic-attribute-type-should-not-be-Object-
https://youtrack.jetbrains.com/issue/IDEA-150816
https://youtrack.jetbrains.com/issue/DBE-2771
Hope this helps someone

Sphinxql - filtering with having

I'm trying to filter query with HAVING but all I get this error:
mysql> SELECT id FROM related_tags GROUP BY application_id HAVING COUNT(*)=10;
ERROR 1064 (42000): sphinxql: syntax error, unexpected IDENT, expecting $end near 'HAVING COUNT(*)=10'
I'm using Sphinx 2.2.6-id64-release, it supports HAVING
This is my index, if it does matter (application_id attribute is for grouping by id).
sql_query = \
SELECT `id`, `id` as `application_id`, `clear_title`\
FROM `applications`\
WHERE `id`>=$start AND `id`<=$end
sql_query_range = SELECT MIN(id),MAX(id) FROM applications
sql_attr_uint = application_id
sql_attr_multi = uint tag_id from query; \
select application_id, tag_id \
from application_tag_stemmed2;
I think you have to make it a virtual attribute, arbitary expressions not allowed in the HAVING clause itself.
SELECT id,COUNT(*) AS cnt FROM related_tags GROUP BY application_id HAVING cnt=10;