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
Related
Can someone please edit this query for psql. I try alot but pgAdmin gives me Error that "d.artifact_type as text" has as Error
SELECT
a.id, a.name, a.description, a.user_id, a.created_at, a.updated_at,
array_agg(row_to_json(c.id, c.first_name, c.last_name, c.email,
b.workspace_id, b.share_id, b.share_with_type, b.write_access)) as users,
array_agg(row_to_json(d.id, d.artifact_name, d.original_artifact_name,
d.artifact_size,d.artifact_type, d.file_address,
d.user_id,d.file_type, d.created_at, f.user_assigned_to)) as files,
array_agg(row_to_json(d.artifact_type as text, d.artifact_type as value)) extensions
FROM workspaces a
LEFT JOIN share_workspaces b ON a.id = b.workspace_id
LEFT JOIN users c ON b.share_id = c.id
LEFT JOIN share_artifacts e ON a.id = e.share_id
LEFT JOIN artifacts d ON d.id = e.artifact_id
LEFT JOIN assigned_artifacts f ON f.artifact_id = d.id
WHERE (a.user_id='${user_id}' AND d.is_deleted is not true)
Group By a.id, a.name, a.description, a.user_id, a.created_at, a.updated_at
ORDER BY a.created_at ASC
I have a Spring Data application connected to PostgreSQL and I enabled the slow log (statements of 100 ms). I noticed a number of these kinds of queries, a few per second:
2022-02-12 15:43:40.247 GMT [29629] LOG: duration: 130.888 ms
bind <unnamed>: SELECT * FROM
(SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR (t.typtype = 'd' AND t.typnotnull)
AS attnotnull,a.atttypmod,a.attlen,t.typtypmod,row_number()
OVER (PARTITION BY a.attrelid ORDER BY a.attnum)
AS attnum, nullif(a.attidentity, '') as attidentity,pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS adsrc,dsc.description,t.typbasetype,t.typtype
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid)
JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid)
JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid)
LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum)
LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid)
LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class')
LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog')
WHERE c.relkind in ('r','p','v','f','m') and a.attnum > 0 AND NOT a.attisdropped
AND n.nspname LIKE 'public' AND c.relname LIKE 'assertion') c WHERE true
ORDER BY nspname,c.relname,attnum
This is not a query my code issuesl my guess is that this query is being issued as part of a JDBC result set mapping. But it looks very inefficient running the same query repeatedly.
The property_assertion table is one of mine, but this query is issued for a number of tables in addition to this one. So this isn't confined to just one query meaning there's no specific code I snippet I can narrow this down to.
Is it a problem seeing these repeatedly, at 100ms a go? Might it be the result of misconfiguration?
"select * from pg_stat_activity" for listing the existing connections, there are 100+ open connections with the state "idle in transaction" with the below query
Query :
SELECT c.oid, a.attnum, a.attname, c.relname, n.nspname,
a.attnotnull OR (t.typtype = 'd' AND t.typnotnull),
a.attidentity != '' OR pg_catalog.pg_get_expr(d.adbin, d.adrelid) LIKE '%nextval(%'
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON (c.relnamespace = n.oid)
JOIN pg_catalog.pg_attribute a ON (c.oid = a.attrelid)
JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid)
LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = a.attrelid AND d.adnum = a.attnum)
JOIN (SELECT 21826 AS oid , 9 AS attnum UNION ALL SELECT 21826, 3) vals ON (c.oid = vals.oid AND a.attnum = vals.attnum)
Google says, its the query for getting the metadata and its generated by framework.
I have checked my code base and there is no place where I called this query. I wonder, why these connections are still in *"idle in transaction" state and is still open; which causing the busy connection.
In pgAdmin tool, when I click on any user-defined function or a procedure on the left side panel, I'm able to see the dependent DB objects like user-defined Types, Schema, Language, Roles etc. in the 'Dependencies' tab.
Is it possible to get the underlying query for those dependencies? Because I need to take the dependent objects for all the procedures and functions from a set of schemas.
Below is the code used in pgAdmin to show Dependents for PostgreSQL 12 plus versions.
This shows up all dependents for all objects. Needs to be filtered out for required objects using oid.
SELECT DISTINCT dep.classid, dep.objid, dep.objsubid, dep.refclassid, dep.refobjid,
dep.deptype,
cl.relkind, ad.adbin, pg_get_expr(ad.adbin, ad.adrelid) as adsrc,
COALESCE(coc.relname, clrw.relname) AS ownertable,
CASE WHEN cl.relname IS NOT NULL AND att.attname IS NOT NULL THEN cl.relname || COALESCE('.' || att.attname, '')
ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname,
fs.srvname, fdw.fdwname, evt.evtname, col.collname, ftsc.cfgname, ftsd.dictname, ftsp.prsname,
ftst.tmplname, ext.extname, syn.synname, pl.polname)
END AS refname,
COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname, colns.nspname, ftscns.nspname,
ftsdns.nspname, ftspns.nspname, ftstns.nspname, synns.nspname) AS dep_obj_schema,
CASE WHEN cl.relkind IS NOT NULL THEN CASE WHEN cl.relkind = 'r' THEN cl.relkind || COALESCE(dep.objsubid::text, '') ELSE cl.relkind END
WHEN tg.oid IS NOT NULL THEN CASE WHEN tg.tgpackageoid != 0 THEN 'Tc'::text ELSE 'Tr'::text END
WHEN ty.oid IS NOT NULL THEN CASE WHEN ty.typtype = 'd' THEN 'd'::text ELSE 'Ty'::text END
WHEN ns.oid IS NOT NULL THEN CASE WHEN ns.nspparent != 0 AND ns.nspcompoundtrigger = false THEN 'Pa'::text ELSE 'n'::text END
WHEN pr.oid IS NOT NULL AND (prtyp.typname = 'trigger' OR prtyp.typname = 'event_trigger') THEN 'Pt'::text
WHEN pr.oid IS NOT NULL THEN CASE WHEN pr.prokind = 'p' THEN 'Procedure'::text ELSE 'Function'::text END
WHEN la.oid IS NOT NULL THEN 'l'::text
WHEN rw.oid IS NOT NULL THEN 'Rl'::text
WHEN co.oid IS NOT NULL THEN CASE WHEN co.contypid > 0 THEN 'Cd' ELSE 'C'::text || contype END
WHEN ad.oid IS NOT NULL THEN 'A'::text
WHEN fs.oid IS NOT NULL THEN 'Fs'::text
WHEN fdw.oid IS NOT NULL THEN 'Fw'::text
WHEN evt.oid IS NOT NULL THEN 'Et'::text
WHEN col.oid IS NOT NULL THEN 'Co'::text
WHEN ftsc.oid IS NOT NULL THEN 'Fc'::text
WHEN ftsp.oid IS NOT NULL THEN 'Fp'::text
WHEN ftsd.oid IS NOT NULL THEN 'Fd'::text
WHEN ftst.oid IS NOT NULL THEN 'Ft'::text
WHEN ext.oid IS NOT NULL THEN 'Ex'::text
WHEN syn.oid IS NOT NULL THEN 'Sy'::text
WHEN pl.oid IS NOT NULL THEN 'Rs'::text
ELSE ''
END AS dep_obj_type
CASE WHEN inhits.inhparent IS NOT NULL THEN '1' ELSE '0' END AS is_inherits,
CASE WHEN inhed.inhparent IS NOT NULL THEN '1' ELSE '0' END AS is_inherited
FROM pg_catalog.pg_depend dep
LEFT JOIN pg_catalog.pg_class cl ON dep.objid=cl.oid
LEFT JOIN pg_catalog.pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum
LEFT JOIN pg_catalog.pg_namespace nsc ON cl.relnamespace=nsc.oid
LEFT JOIN pg_catalog.pg_proc pr ON dep.objid=pr.oid
LEFT JOIN pg_catalog.pg_namespace nsp ON pr.pronamespace=nsp.oid
LEFT JOIN pg_catalog.pg_trigger tg ON dep.objid=tg.oid
LEFT JOIN pg_catalog.pg_type ty ON dep.objid=ty.oid
LEFT JOIN pg_catalog.pg_namespace nst ON ty.typnamespace=nst.oid
LEFT JOIN pg_catalog.pg_constraint co ON dep.objid=co.oid
LEFT JOIN pg_catalog.pg_class coc ON co.conrelid=coc.oid
LEFT JOIN pg_catalog.pg_namespace nso ON co.connamespace=nso.oid
LEFT JOIN pg_catalog.pg_rewrite rw ON dep.objid=rw.oid
LEFT JOIN pg_catalog.pg_class clrw ON clrw.oid=rw.ev_class
LEFT JOIN pg_catalog.pg_namespace nsrw ON clrw.relnamespace=nsrw.oid
LEFT JOIN pg_catalog.pg_language la ON dep.objid=la.oid
LEFT JOIN pg_catalog.pg_namespace ns ON dep.objid=ns.oid
LEFT JOIN pg_catalog.pg_attrdef ad ON ad.oid=dep.objid
LEFT JOIN pg_catalog.pg_foreign_server fs ON fs.oid=dep.objid
LEFT JOIN pg_catalog.pg_foreign_data_wrapper fdw ON fdw.oid=dep.objid
LEFT JOIN pg_catalog.pg_type prtyp ON prtyp.oid = pr.prorettype
LEFT JOIN pg_catalog.pg_inherits inhits ON (inhits.inhrelid=dep.objid)
LEFT JOIN pg_catalog.pg_inherits inhed ON (inhed.inhparent=dep.objid)
LEFT JOIN pg_catalog.pg_event_trigger evt ON evt.oid=dep.objid
LEFT JOIN pg_catalog.pg_collation col ON col.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace colns ON col.collnamespace=colns.oid
LEFT JOIN pg_catalog.pg_ts_config ftsc ON ftsc.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace ftscns ON ftsc.cfgnamespace=ftscns.oid
LEFT JOIN pg_catalog.pg_ts_dict ftsd ON ftsd.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace ftsdns ON ftsd.dictnamespace=ftsdns.oid
LEFT JOIN pg_catalog.pg_ts_parser ftsp ON ftsp.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace ftspns ON ftsp.prsnamespace=ftspns.oid
LEFT JOIN pg_catalog.pg_ts_template ftst ON ftst.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace ftstns ON ftst.tmplnamespace=ftstns.oid
LEFT JOIN pg_catalog.pg_extension ext ON ext.oid=dep.objid
LEFT JOIN pg_catalog.pg_synonym syn ON syn.oid=dep.objid
LEFT JOIN pg_catalog.pg_namespace synns ON syn.synnamespace=synns.oid
LEFT JOIN pg_catalog.pg_policy pl ON pl.oid=dep.objid
WHERE
classid IN ( SELECT oid FROM pg_catalog.pg_class WHERE relname IN
('pg_class', 'pg_constraint', 'pg_conversion', 'pg_language', 'pg_proc', 'pg_rewrite', 'pg_namespace',
'pg_trigger', 'pg_type', 'pg_attrdef', 'pg_event_trigger', 'pg_foreign_server', 'pg_foreign_data_wrapper',
'pg_collation', 'pg_ts_config', 'pg_ts_dict', 'pg_ts_parser', 'pg_ts_template', 'pg_extension',
'pg_synonym', 'pg_policy'));
I'm stuck with a SQL query. I'm making a subquery in the select clause and db2 prompts a -119 error telling:
"An expression starting with "FACILITY_ID" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQL Code: -119, SQL State: 42803"
I don't know how to include NUMTAGS in the GROUP BY. I tried including the BC.ITEM in the GROUP BY clause with no result. I don't know how exactly to look for this in the web, and the forums I looked at were no useful.
If someone could explain me how to mend this or paste a link where I could look for a solution, I would be grateful.
The SQL query is with DB2 and it's down here:
SELECT SS.NAME, B.DESTINATION_ID, P.DESCRIPTION, B.LAST_READ_DATE, B.LABEL,
(SELECT COUNT(BC.ITEM)
FROM PROJECT_DB.BOX_CONTENT BC
WHERE BC.FACILITY_ID = B.FACILITY_ID
AND BC.BOX_ID = B.BOX_ID
GROUP BY BC.ITEM) AS NUMTAGS,
B.BOX_ID
FROM PROJECT_DB.BOX B
INNER JOIN MAINDB.DESTINATION P ON B.DESTINATION_ID = P.DESTINATION_ID
INNER JOIN MAINDB.WAREHOUSE_DESTINATION_SECTION WH
ON B.DESTINATION_ID = WH.DESTINATION_ID
AND B.WAREHOUSE_ID = WH.WAREHOUSE_ID
INNER JOIN MAINDB.SECTION S ON S.SECTION = WH.SECTION
AND S.SECTION_TYPE = B.SECTION_TYPE
INNER JOIN MAINDB.DESTINATION_SET SS
ON SS.DESTINATION_SET_ID = S.DESTINATION_SET_ID
WHERE B.WAREHOUSE_ID = 100
GROUP BY B.BOX_ID, B.FACILITY_ID, B.DESTINATION_ID, B.LAST_READ_DATE, B.LABEL, P.DESCRIPTION, SS.NAME
You can correct the statement by: v including the columns in the GROUP
BY clause that are in the SELECT clause, or v removing the columns
from the SELECT clause.
From: DB2 documentation.
You need to put ALL selected columns in your GROUP BY...
Since you're using a scalar sub-select, I don't think you need a GROUP BY clause on either of your statements. Try this:
SELECT
SS.NAME,
B.DESTINATION_ID,
P.DESCRIPTION,
B.LAST_READ_DATE,
B.LABEL,
(SELECT COUNT(BC.ITEM)
FROM PROJECT_DB.BOX_CONTENT BC
WHERE BC.FACILITY_ID = B.FACILITY_ID
AND BC.BOX_ID = B.BOX_ID
) AS NUMTAGS,
B.BOX_ID
FROM PROJECT_DB.BOX B
JOIN MAINDB.DESTINATION P
ON B.DESTINATION_ID = P.DESTINATION_ID
JOIN MAINDB.WAREHOUSE_DESTINATION_SECTION WH
ON B.DESTINATION_ID = WH.DESTINATION_ID
AND B.WAREHOUSE_ID = WH.WAREHOUSE_ID
JOIN MAINDB.SECTION S
ON S.SECTION = WH.SECTION
AND S.SECTION_TYPE = B.SECTION_TYPE
JOIN MAINDB.DESTINATION_SET SS
ON SS.DESTINATION_SET_ID = S.DESTINATION_SET_ID
WHERE B.WAREHOUSE_ID = 100
My final working query is this down here. I think I had the wrong tables referenced at the "group by" or something similar:
SELECT SS.NAME, P.DESTINATION_ID, P.DESCRIPTION, B.LAST_READ_DATE, B.LABEL,
(SELECT COUNT(BC.ITEM)
FROM PROJECT_DB.BOX_CONTENT BC
WHERE BC.ID_FACILITY = B.ID_FACILITY
AND BC.ID_BOX = B.ID_BOX
GROUP BY BC.ITEM) AS NUMTAGS,
B.BOX_ID, B.FACILITY_ID
FROM PROJECT_DB.BOX B
INNER JOIN MAINDB.DESTINATION P ON B.DESTINATION_ID = P.DESTINATION_ID
INNER JOIN MAINDB.WAREHOUSE_DESTINATION_SECTION WH
ON WH.WAREHOUSE_ID = B.WAREHOUSE_ID
AND WH.ID_DESTINATION = B.ID_DESTINATION
INNER JOIN MAINDB.SECTION S ON S.SECTION = WH.SECTION
AND S.SECTION_TYPE = B.SECTION_TYPE
INNER JOIN MAINDB.DESTINATION_SET SS ON SS.DESTINATION_SET_ID = S.DESTINATION_SET_ID
WHERE B.WAREHOUSE_ID = 100
GROUP BY B.BOX_ID, B.FACILITY_ID, P.DESTINATION_ID, B.LAST_READ_DATE, B.LABEL, P.DESCRIPTION, SS.NAME
WITH UR