Postgresql: ERROR: unrecognized join type: 7 - sql

I have a lot of same structured PostgreSQL databases on same server
PostgreSQL 9.6.1 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413, 64-bit
And SQL going below, giving next error only on some of them:
SQLSTATE[XX000]: Internal error: 7 ERROR: unrecognized join type: 7
On the other databases with same structure it works fine. If i will decrease number of id_product values in query, it starts working
SELECT client_tt.id_client_tt as id,
client_tt.tt_name as caption,
SUM(delivery_data.money) AS value,
client_tt.latitude as lat, client_tt.longitude as lon
FROM delivery_data
JOIN client_tt on (client_tt.id_client_tt = delivery_data.id_client_tt)
WHERE (delivery_date BETWEEN '2017-01-01' AND '2017-03-31')
AND client_tt.latitude != 0 AND client_tt.longitude != 0
AND delivery_data.delivery_group_id IN (58)
AND delivery_data.id_product = ANY ( VALUES(7153), (9812), (5411), (9801), (5039), (7010), (4632), (5316), (1727), (9785), (5622), (8533), (5031), (756), (2769), (3239), (8680), (9775), (7958), (8630), (4059), (7185), (8261), (3652), (6950), (2148), (7828), (8695), (6228), (9803), (8112), (9536), (6466), (4447), (359), (3310), (7332), (4512), (5700), (7981), (4650), (9223), (8519), (4519), (9784), (8689), (8545), (541), (5134), (4081), (774), (6068), (7038), (6346), (7956), (10005), (9090), (537), (2300), (526), (4485), (8106), (3445), (559), (8256), (8825), (10085), (8874), (6680), (357), (6198), (2556), (5058), (7938), (5352), (8940), (2741), (4667), (6560), (4137), (5733), (763), (7088), (2486), (6512), (6642), (6674), (752), (4105), (2554), (6349), (7333), (6922), (3882), (2768), (3700), (9799), (9866), (9770), (533), (7384), (8468), (9320), (343), (5506), (4212), (8922), (10021), (6696), (9144), (3242), (5504), (6210), (5968), (5721), (2886), (8678), (7928), (7131), (4020), (9776), (6021), (6136), (6303), (9686), (7030), (8855), (6686), (9556), (10009), (1903), (8876), (6503), (2497), (8697), (10198), (2155), (5497), (5865), (8282), (4449), (7774), (6700), (7934), (8522), (9289), (10003), (8081), (5429), (547), (8320), (6305), (556), (2605), (8433), (9441), (5035), (9507), (6980), (2992), (5019), (7613), (9991), (2323), (4513), (3594), (8014), (737), (6298), (8449), (6285), (5790), (8266), (5041), (748), (7366), (9574), (5062), (5346), (2349), (5259), (8527), (5414), (5698), (6058), (7327), (4647), (8567), (4242), (8474), (3669), (3161), (7848), (6643), (8321), (8410), (530), (5415), (9097), (6031), (7219), (9768), (6793), (7646), (7049), (10079), (4761), (7324), (8679), (5032), (5141), (6556), (546), (7297), (358), (736), (6678), (8593), (5034), (8161), (9779), (4518), (5558), (758), (739), (4525), (9663), (8515), (8621), (3673), (535), (10094), (3443), (6933), (7717), (4248), (5139), (8123), (9920), (2355), (9936), (8307), (10228), (3619), (7273), (9162), (7279), (10011), (7921), (9462), (542), (9692), (5043), (5376), (8096), (8436), (5418), (10098), (2990), (5193), (6651), (1860), (6135), (8889), (4241), (3596), (6542), (2354), (762), (7360), (8326), (531), (5701), (5132), (4643), (6280), (9323), (4523), (6291), (8836), (3292), (5038), (4668), (3276), (560), (7852), (2299), (7120), (5633), (545), (9788), (4795), (2793), (9727), (6641), (7631), (553), (6670), (3004), (2984), (3293), (2865), (5094), (7867), (9322), (4249), (4672), (5263), (6197), (6689), (3456), (6137), (7599), (3576), (3577), (10096), (9763), (2867), (6276), (6316), (5404), (2303), (8710), (351), (5135), (5547), (2374), (8310), (8699), (10082), (2559), (7203), (7016), (5325), (3888), (742), (9398), (5322), (6134), (10004), (764), (9790), (5196), (7152), (9669), (7596), (8709), (9580), (7962), (1905), (2548), (4080), (5198), (9302), (9434), (5136), (552), (3767), (4243), (5242), (4654), (6645), (4670), (2898), (7975), (3175), (6608), (2490), (3210), (8183), (7608), (9496), (9564), (4777), (7605), (4804), (7601), (3211), (9164), (9913), (2888), (9767), (9167), (3291), (10076), (8272), (2369), (7597), (3138), (8529), (769), (9460), (9537), (3296), (9687), (8548), (766), (7312), (5018), (9563), (4540), (5421), (8973), (8636), (10099), (5373), (9824), (5095), (7017), (9540), (3621), (2985), (8440), (3889), (5374), (6690), (8514), (8405), (9233), (6761), (4373), (6661), (7253), (9458), (528), (4448), (3711), (8431), (9490), (544), (5929), (4077), (9725), (4508), (8811), (3298), (8863), (9108), (6788), (6362), (2697), (6610), (360), (6133), (8383), (780), (8406), (5082), (10084), (4078), (10018), (5138), (8108), (9766), (6652), (2547), (9491), (9409), (5045), (3651), (561), (8425), (8442), (9130), (9109), (3442), (4101), (6662), (8364), (2269), (4240), (4645), (2892), (4717), (5410), (5987), (8075), (8703), (3772), (746), (7598), (9780), (7606), (5417), (5509), (3898), (344), (2820), (3748), (6665), (7110), (776), (5507), (5706), (7158), (3765), (6943), (5324), (5513), (7097), (7923), (7924), (5750), (6340), (4486), (5286), (6703), (6640), (6694), (9566), (9912), (6616), (6656), (8671), (9791), (4522), (6912), (3090), (8661), (757), (3954), (527), (773), (2494), (345), (4168), (6151), (3595), (9764), (5726), (10016), (1939), (7966), (6288), (8711), (1900), (7894), (749), (3099), (6403), (8990), (772), (2558), (6281), (548), (9786), (8089), (8693), (9277), (10012), (9116), (7034), (740), (4247), (8706), (10233), (8090), (8682), (7615), (7667), (9291), (6352), (8829), (8698), (550), (6660), (9661), (5377), (5912), (10100), (9499), (10196), (549), (8427), (3771), (5372), (4743), (1519), (2324), (8117), (7963), (9032), (2301), (8141), (9140), (745), (4757), (7220), (6679), (2147), (5293), (5336), (9425), (8807), (4079), (3622), (6311), (8806), (9498), (2899), (4445), (7890), (5515), (8853), (765), (2557), (6047), (10002), (5514), (4100), (2890), (733), (4139), (1898), (555), (6059), (554), (5966), (6505), (3883), (6513), (8315), (7172), (5428), (9102), (2555), (8838), (2302), (4790), (8049), (8323), (6867), (2866), (10104), (6209), (9082), (9110), (6402), (9864), (7211), (8064), (3899), (6006), (7127), (779), (5013), (1997), (738), (7675), (4141), (7164), (7371), (5725), (8700), (4669), (6376), (9085), (3241), (8103), (6511), (2296), (5137), (5919), (7929), (2891), (3446), (10103))
GROUP BY client_tt.id_client_tt;

Fixed after upgrading from 9.6.1 to 9.6.2

Related

Counting number in Spark SQL

I'm new to Spark SQL and my task is to count number of airports by state. I have already prepared my code but after execution the below error appears. Could you please point what is wrong here?
result_number_of_airports = spark.sql(
"SELECT state, COUNT(DISTINCT airport) AS number_of_airports \
FROM airports \
GROUP BY state \
ORDER BY number_of_airports DESC")
Schema
airports:pyspark.sql.dataframe.DataFrame
IATA_CODE:string
AIRPORT:string
CITY:string
STATE:string
COUNTRY:string
LATITUDE:string
LONGITUDE:string
Error message
AnalysisException: cannot resolve '`state`' given input columns: [airports.ActualElapsedTime, airports.AirTime, airports.AirlineID, airports.ArrDel15, airports.ArrDelay, airports.ArrDelayMinutes, airports.ArrTime, airports.ArrTimeBlk, airports.ArrivalDelayGroups, airports.CRSArrTime, airports.CRSDepTime, airports.CRSElapsedTime, airports.CancellationCode, airports.Cancelled, airports.Carrier, airports.CarrierDelay, airports.DayOfWeek, airports.DayofMonth, airports.DepDel15, airports.DepDelay, airports.DepDelayMinutes, airports.DepTime, airports.DepTimeBlk, airports.DepartureDelayGroups, airports.Dest, airports.DestAirportID, airports.DestAirportSeqID, airports.DestCityMarketID, airports.DestCityName, airports.DestState, airports.DestStateFips, airports.DestStateName, airports.DestWac, airports.Distance, airports.DistanceGroup, airports.Div1Airport, airports.Div1AirportID, airports.Div1AirportSeqID, airports.Div1LongestGTime, airports.Div1TailNum, airports.Div1TotalGTime, airports.Div1WheelsOff, airports.Div1WheelsOn, airports.Div2Airport, airports.Div2AirportID, airports.Div2AirportSeqID, airports.Div2LongestGTime, airports.Div2TailNum, airports.Div2TotalGTime, airports.Div2WheelsOff, airports.Div2WheelsOn, airports.Div3Airport, airports.Div3AirportID, airports.Div3AirportSeqID, airports.Div3LongestGTime, airports.Div3TailNum, airports.Div3TotalGTime, airports.Div3WheelsOff, airports.Div3WheelsOn, airports.Div4Airport, airports.Div4AirportID, airports.Div4AirportSeqID, airports.Div4LongestGTime, airports.Div4TailNum, airports.Div4TotalGTime, airports.Div4WheelsOff, airports.Div4WheelsOn, airports.Div5Airport, airports.Div5AirportID, airports.Div5AirportSeqID, airports.Div5LongestGTime, airports.Div5TailNum, airports.Div5TotalGTime, airports.Div5WheelsOff, airports.Div5WheelsOn, airports.DivActualElapsedTime, airports.DivAirportLandings, airports.DivArrDelay, airports.DivDistance, airports.DivReachedDest, airports.Diverted, airports.FirstDepTime, airports.FlightDate, airports.FlightNum, airports.Flights, airports.LateAircraftDelay, airports.LongestAddGTime, airports.Month, airports.NASDelay, airports.Origin, airports.OriginAirportID, airports.OriginAirportSeqID, airports.OriginCityMarketID, airports.OriginCityName, airports.OriginState, airports.OriginStateFips, airports.OriginStateName, airports.OriginWac, airports.Quarter, airports.SecurityDelay, airports.TailNum, airports.TaxiIn, airports.TaxiOut, airports.TotalAddGTime, airports.UniqueCarrier, airports.WeatherDelay, airports.WheelsOff, airports.WheelsOn, airports.Year, airports._c109]; line 1 pos 87;
Temp table was not correctly assigned.
I have changed from
temp_table_name = "flights"
flights.createOrReplaceTempView(temp_table_name)
temp_table_name = "airlines"
airlines.createOrReplaceTempView(temp_table_name)
temp_table_name = "airports"
airports.createOrReplaceTempView(temp_table_name)
to
temp_table_name1 = "flights"
flights.createOrReplaceTempView(temp_table_name1)
temp_table_name2 = "airlines"
flights.createOrReplaceTempView(temp_table_name2)
temp_table_name3 = "airports"
flights.createOrReplaceTempView(temp_table_name3)

Missing right parenthesis issue in Oracle

select
aplikasi0_.ID_APLIKASI as ID_APLIKASI1_0_,
aplikasi0_.created_by as created_by2_0_,
aplikasi0_.created_dt as created_dt3_0_,
aplikasi0_.end_dt as end_dt4_0_,
aplikasi0_.modified_by as modified_by5_0_,
aplikasi0_.modified_dt as modified_dt6_0_,
aplikasi0_.status as status7_0_,
aplikasi0_.ID_AGENT as ID_AGENT8_0_,
aplikasi0_.ID_BANK_OPERATION as ID_BANK_OPERATION9_0_,
aplikasi0_.ID_CABANG as ID_CABANG10_0_,
aplikasi0_.ID_CENTRO as ID_CENTRO11_0_,
aplikasi0_.ID_HUBUNGAN_DENGAN_PEMOHON as ID_HUBUNGAN_DENGA12_0_,
aplikasi0_.ID_INDUSTRI as ID_INDUSTRI13_0_,
aplikasi0_.ID_JABATAN as ID_JABATAN14_0_,
aplikasi0_.ID_JENIS_KENDARAAN as ID_JENIS_KENDARAA15_0_,
aplikasi0_.ID_JENIS_PEMBIAYAAN as ID_JENIS_PEMBIAYA16_0_,
aplikasi0_.ID_JENIS_PRODUK as ID_JENIS_PRODUK17_0_,
aplikasi0_.ID_KARYAWAN as ID_KARYAWAN18_0_,
aplikasi0_.ID_KATEGORI_PRODUK as ID_KATEGORI_PRODU19_0_,
aplikasi0_.ID_MEDIA as ID_MEDIA20_0_,
aplikasi0_.ID_MERK_BARANG as ID_MERK_BARANG21_0_,
aplikasi0_.ID_MODEL_BARANG as ID_MODEL_BARANG22_0_,
aplikasi0_.ID_OUTLET_DEALER as ID_OUTLET_DEALER23_0_,
aplikasi0_.ID_PORTOFOLIO as ID_PORTOFOLIO24_0_,
aplikasi0_.ID_PROGRAM_MARKETING as ID_PROGRAM_MARKET25_0_,
aplikasi0_.ID_SUB_PRODUK as ID_SUB_PRODUK26_0_,
aplikasi0_.ID_SUMBER_APLIKASI as ID_SUMBER_APLIKAS27_0_,
aplikasi0_.ID_SURVEYOR as ID_SURVEYOR28_0_,
aplikasi0_.ID_TIPE_APLIKASI as ID_TIPE_APLIKASI29_0_,
aplikasi0_.ID_TIPE_BARANG as ID_TIPE_BARANG30_0_,
aplikasi0_.ID_TIPE_FINANCIAL as ID_TIPE_FINANCIAL31_0_,
aplikasi0_.ID_TIPE_KONSUMEN as ID_TIPE_KONSUMEN32_0_,
aplikasi0_.ID_TIPE_TOKO as ID_TIPE_TOKO33_0_,
aplikasi0_.ID_WARNA as ID_WARNA34_0_,
aplikasi0_.KETERANGAN as KETERANGAN35_0_,
aplikasi0_.ID_KONSUMEN as ID_KONSUMEN58_0_,
aplikasi0_.ID_LEADS as ID_LEADS59_0_,
aplikasi0_.LIST_STOK as LIST_STOK36_0_,
aplikasi0_.MEDIATOR as MEDIATOR37_0_,
aplikasi0_.NAMA_TOKO as NAMA_TOKO38_0_,
aplikasi0_.NO_BOOKING_LAMA as NO_BOOKING_LAMA39_0_,
aplikasi0_.NO_BPKB as NO_BPKB40_0_,
aplikasi0_.NO_INVOICE as NO_INVOICE41_0_,
aplikasi0_.NO_MESIN as NO_MESIN42_0_,
aplikasi0_.NO_MOU as NO_MOU43_0_,
aplikasi0_.NO_RANGKA as NO_RANGKA44_0_,
aplikasi0_.ID_PEMBIAYAAN as ID_PEMBIAYAAN60_0_,
aplikasi0_.STATUS_APLIKASI as STATUS_APLIKASI45_0_,
aplikasi0_.STATUS_BPJS as STATUS_BPJS46_0_,
aplikasi0_.STATUS_DUKCAPIL as STATUS_DUKCAPIL47_0_,
aplikasi0_.STATUS_MINAT as STATUS_MINAT48_0_,
aplikasi0_.STATUS_SLIK as STATUS_SLIK49_0_,
aplikasi0_.STNK_ATAS_NAMA as STNK_ATAS_NAMA50_0_,
aplikasi0_.TAHUN as TAHUN51_0_,
aplikasi0_.TGL_APLIKASI as TGL_APLIKASI52_0_,
aplikasi0_.TGL_BAST as TGL_BAST53_0_,
aplikasi0_.TGL_JANJI_SURVEY as TGL_JANJI_SURVEY54_0_,
aplikasi0_.TGL_JT_INVOICE as TGL_JT_INVOICE55_0_,
aplikasi0_.TGL_JT_MOU as TGL_JT_MOU56_0_,
aplikasi0_.TOTAL_BARANG as TOTAL_BARANG57_0_,
(SELECT aplikasi0_.h.ID_APLIKASI
FROM MMF_TRX_HISTORI_APPROVAL h
WHERE h.ID_APLIKASI = aplikasi0_.ID_APLIKASI AND ROWNUM = 1
ORDER BY h.TGL_APPROVAL DESC
LIMIT 1) as formula1_
from
MMF_LOS.MMF_TRX_APLIKASI aplikasi0_
where
aplikasi0_.ID_TIPE_APLIKASI = 'REJ';
You have used LIMIT which is not the valid keyword in oracle.
Replace LIMIT 1 with fetch first row only. (Oracle 12c or higher)
Cheers!!

Oracle throws ORA-00911 invalid character error while executing a query generated by entity framework 6.0

I'm having problems with the query below which is generated by Entity Framewrok 6.0. When I remove where clause query is being executed well. But I cant see the problem on where clause. Can you please help me?
{SELECT
"Extent1"."ID" AS "ID",
"Extent1"."STATECODE" AS "STATECODE",
"Extent1"."FIRMAID" AS "FIRMAID",
"Extent1"."ILID" AS "ILID",
"Extent1"."ILCEID" AS "ILCEID",
"Extent1"."PLANTURID" AS "PLANTURID",
"Extent1"."ETUDTURID" AS "ETUDTURID",
"Extent1"."ETUDAMACID" AS "ETUDAMACID",
"Extent1"."DILIMID" AS "DILIMID",
"Extent1"."ACIKLAMA" AS "ACIKLAMA",
"Extent1"."BASVURUTARIHI" AS "BASVURUTARIHI",
"Extent1"."ALAN" AS "ALAN",
"Extent1"."OLCEK" AS "OLCEK",
"Extent1"."CREATETIME" AS "CREATETIME",
"Extent1"."UPDATETIME" AS "UPDATETIME",
"Extent1"."CREATEUSERID" AS "CREATEUSERID",
"Extent1"."UPDATEUSERID" AS "UPDATEUSERID",
"Extent2"."ID" AS "ID1",
"Extent2"."KOD" AS "KOD",
"Extent2"."AD" AS "AD",
"Extent2"."CREATETIME" AS "CREATETIME1",
"Extent2"."UPDATETIME" AS "UPDATETIME1",
"Extent2"."CREATEUSERID" AS "CREATEUSERID1",
"Extent2"."UPDATEUSERID" AS "UPDATEUSERID1",
"Extent3"."ID" AS "ID2",
"Extent3"."KOD" AS "KOD1",
"Extent3"."AD" AS "AD1",
"Extent3"."PLANTURID" AS "PLANTURID1",
"Extent3"."CREATETIME" AS "CREATETIME2",
"Extent3"."UPDATETIME" AS "UPDATETIME2",
"Extent3"."CREATEUSERID" AS "CREATEUSERID2",
"Extent3"."UPDATEUSERID" AS "UPDATEUSERID2",
"Extent4"."ID" AS "ID3",
"Extent4"."VERGINUMARASI" AS "VERGINUMARASI",
"Extent4"."EMAIL" AS "EMAIL",
"Extent4"."FIRMAADI" AS "FIRMAADI",
"Extent4"."BUROTESCILNUMARASI" AS "BUROTESCILNUMARASI",
"Extent4"."TELEFON" AS "TELEFON",
"Extent4"."ADRES" AS "ADRES",
"Extent4"."ILID" AS "ILID1",
"Extent4"."ILCEID" AS "ILCEID1",
"Extent4"."MAHALLEID" AS "MAHALLEID",
"Extent4"."VERGIDAIRESIID" AS "VERGIDAIRESIID",
"Extent4"."USERID" AS "USERID",
"Extent4"."NODEID" AS "NODEID",
"Extent4"."CREATETIME" AS "CREATETIME3",
"Extent4"."UPDATETIME" AS "UPDATETIME3",
"Extent4"."CREATEUSERID" AS "CREATEUSERID3",
"Extent4"."UPDATEUSERID" AS "UPDATEUSERID3",
"Extent5"."FEATUREID" AS "FEATUREID",
"Extent5"."ADI_NUMARASI" AS "ADI_NUMARASI",
"Extent5"."UAVTKOD" AS "UAVTKOD",
"Extent6"."FEATUREID" AS "FEATUREID1",
"Extent6"."ADI_NUMARASI" AS "ADI_NUMARASI1",
"Extent6"."UAVTKOD" AS "UAVTKOD1",
"Extent6"."ILKOD" AS "ILKOD",
"Extent7"."ID" AS "ID4",
"Extent7"."ENLEM" AS "ENLEM",
"Extent7"."BOYLAM" AS "BOYLAM",
"Extent7"."DILIMI" AS "DILIMI",
"Extent7"."MERIDYEN" AS "MERIDYEN",
"Extent7"."ILADI" AS "ILADI",
"Extent7"."ILID" AS "ILID2",
"Extent8"."ID" AS "ID5",
"Extent8"."KOD" AS "KOD2",
"Extent8"."AD" AS "AD2",
"Extent8"."CREATETIME" AS "CREATETIME4",
"Extent8"."UPDATETIME" AS "UPDATETIME4",
"Extent8"."CREATEUSERID" AS "CREATEUSERID4",
"Extent8"."UPDATEUSERID" AS "UPDATEUSERID4"
FROM "JEOLOJI"."PROJE" "Extent1"
INNER JOIN "JEOLOJI"."ETUDAMAC" "Extent2" ON "Extent1"."ETUDAMACID" = "Extent2"."ID"
INNER JOIN "JEOLOJI"."ETUDTUR" "Extent3" ON "Extent1"."ETUDTURID" = "Extent3"."ID"
INNER JOIN "JEOLOJI"."FIRMA" "Extent4" ON "Extent1"."FIRMAID" = "Extent4"."ID"
INNER JOIN "JEOLOJI"."IL" "Extent5" ON "Extent1"."ILID" = "Extent5"."FEATUREID"
LEFT OUTER JOIN "JEOLOJI"."ILCE" "Extent6" ON "Extent1"."ILCEID" = "Extent6"."FEATUREID"
INNER JOIN "JEOLOJI"."DILIM" "Extent7" ON "Extent1"."DILIMID" = "Extent7"."ID"
INNER JOIN "JEOLOJI"."PLANTUR" "Extent8" ON "Extent1"."PLANTURID" = "Extent8"."ID"
WHERE ((1 = (CASE WHEN (( NVL(INSTR(LOWER(CASE WHEN ("Extent1"."ACIKLAMA" IS NULL) THEN '' ELSE "Extent1"."ACIKLAMA" END), LOWER('Ma')), 0) ) = 1) THEN 1 WHEN (( NVL(INSTR(LOWER(CASE WHEN ("Extent1"."ACIKLAMA" IS NULL) THEN '' ELSE "Extent1"."ACIKLAMA" END), LOWER('Ma')), 0) ) <> 1) THEN 0 END)) AND (22 <> "Extent1"."FIRMAID"))}
I solved the problem.
We are marking our string types in c# with StringLength attribute to prevent Entity Framework to create them as NCLOB columns on Oracle. Then Entity Framework generates columns with type nvarchar for c# propeties marked with StringLenth attribute.
In this query the where clause works fine with varchar2 because of the qoutes(as I learned from my Db profession friend.) So I changed the types of the columns and its solved.

JPA forming query which fails at program running

I am doing the following query in JPA:
#NamedQuery(name = PlayerSkill.DELETE_ALL_BOT_DATA,
query = "DELETE FROM PlayerSkill s WHERE s.player.id " +
"IN (SELECT p.id FROM Player p WHERE p.team.id " +
"IN (SELECT t.id FROM Manager m JOIN m.teamInfo t WHERE m.localUserId IS NULL))")
And receiving the following exception when calling appropriate DAO function, which is calling the JPA named query using executeUpdate:
7818 [Thread-12] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42601
7818 [Thread-12] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: syntax error at or near "cross"
Position: 30
7828 [Thread-12] ERROR c.m.s.threads.ServerInitializer - null
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[AbstractEntityManagerImpl.class:4.2.8.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) ~[AbstractEntityManagerImpl.class:4.2.8.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397) ~[AbstractEntityManagerImpl.class:4.2.8.Final]
at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:111) ~[AbstractQueryImpl.class:4.2.8.Final]
at com.magnifi.pennantrace.dao.player.PlayerSkillDAO.deleteBotTeamsData(PlayerSkillDAO.java:25) ~[PlayerSkillDAO.class:na]
at com.magnifi.schedserv.seasonstartend.SeasonGeneration.deleteAllBotRelatedData(SeasonGeneration.java:1457) ~[SeasonGeneration.class:na]
at com.magnifi.schedserv.seasonstartend.SeasonGeneration.generateSeason(SeasonGeneration.java:109) ~[SeasonGeneration.class:na]
at com.magnifi.schedserv.threads.ServerInitializer.generateEndStart(ServerInitializer.java:161) [ServerInitializer.class:na]
at com.magnifi.schedserv.threads.ServerInitializer.initSystem(ServerInitializer.java:80) [ServerInitializer.class:na]
at com.magnifi.schedserv.threads.SchedulerThread.run(SchedulerThread.java:38) [SchedulerThread.class:na]
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) ~[SQLStateConversionDelegate.class:4.2.8.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[StandardSQLExceptionConverter.class:4.2.8.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) ~[SqlExceptionHelper.class:4.2.8.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) ~[SqlExceptionHelper.class:4.2.8.Final]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189) ~[ResultSetReturnImpl.class:4.2.8.Final]
at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:108) ~[BasicExecutor.class:4.2.8.Final]
at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:77) ~[BasicExecutor.class:4.2.8.Final]
at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:124) ~[DeleteExecutor.class:4.2.8.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) ~[QueryTranslatorImpl.class:4.2.8.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282) ~[HQLQueryPlan.class:4.2.8.Final]
at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1215) ~[SessionImpl.class:4.2.8.Final]
at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) ~[QueryImpl.class:4.2.8.Final]
at org.hibernate.ejb.QueryImpl.internalExecuteUpdate(QueryImpl.java:198) ~[QueryImpl.class:4.2.8.Final]
at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:102) ~[AbstractQueryImpl.class:4.2.8.Final]
... 6 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"
Position: 30
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363) ~[postgresql-9.3-1101.jdbc4.jar:na]
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:100) ~[tomcat-dbcp.jar:8.0.3]
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:100) ~[tomcat-dbcp.jar:8.0.3]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186) ~[ResultSetReturnImpl.class:4.2.8.Final]
... 15 common frames omitted
7832 [Thread-12] ERROR c.m.s.threads.SchedulerThread - null
javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:72) ~[TransactionImpl.class:4.2.8.Final]
at com.magnifi.schedserv.threads.SchedulerThread.run(SchedulerThread.java:39) ~[SchedulerThread.class:na]
The real sql query on that exception is:
delete from bb_player_skills cross join bb_players player1_ where id in (select player2_.id from bb_players player2_ where player2_.team_id in (select teaminfo4_.id from bb_manager manager3_ inner join bb_team_info teaminfo4_ on manager3_.bb_team_info_id=teaminfo4_.id where manager3_.local_user_id is null))
I can't understand why its forming the query using "cross" as it says in the error log.
For a different table the same query works well:
#NamedQuery(name=PlayerStat.DELETE_BOT_DATA,
query = "DELETE FROM PlayerStat s WHERE s.player.id " +
"IN (SELECT p.id FROM Player p WHERE p.team.id " +
"IN (SELECT t.id FROM Manager m JOIN m.teamInfo t WHERE m.localUserId IS NULL))")
And real sql formed by this query is not containing "cross":
delete from bb_player_stat where bb_players_id in (select player1_.id from bb_players player1_ where player1_.team_id in (select teaminfo3_.id from bb_manager manager2_ inner join bb_team_info teaminfo3_ on manager2_.bb_team_info_id=teaminfo3_.id where manager2_.local_user_id is null))
The relation of tables is same also: player skill is one to one to players , same as player stat
EDIT:
for player skills (the one where cross is used) the entity:
#JSON(include=false)
private Player player;
#Id
#OneToOne(fetch=FetchType.LAZY)
#JoinColumn(name="bb_players_id", nullable=false)
public Player getPlayer() {
return this.player;
}
And for PlayerStat:
private Player player;
#OneToOne(fetch=FetchType.LAZY)
#JoinColumn(name="bb_players_id", nullable=false)
public Player getPlayer() {
return this.player;
}
In the Player entity:
#OneToOne(mappedBy="player", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
public PlayerSkill getPlayerSkill() {
return this.playerSkill;
}
#OneToOne(mappedBy="player", cascade=CascadeType.ALL)
public PlayerStat getPlayerStats() {
return this.playerStats;
}

Error creating geography element using "STGeomFromText( 'LINESTRING(..." - SQL 2008

I am getting the following error when trying to create geography elements in sql 2008:
NET Framework error occurred during execution of user-defined routine
or aggregate "geography": System.ArgumentException: 24200: The
specified input does not represent a valid geography instance.
System.ArgumentException:
Some example queries are:
select geography::STGeomFromText( 'LINESTRING(
53.4707 -2.24758,53.4708 -2.25079,53.4733 -2.2597,53.4743 -2.24812,53.4747 -2.24119,53.4756 -2.26244,53.4765 -2.24278,53.4805 -2.28457,53.4909 -2.37892,53.5272 -2.36252,53.7159 -2.56899,53.7165 -2.56208,53.7183 -2.62195,53.7212 -2.55478,53.7439 -2.48239,53.7443 -2.48351,53.7446 -2.48767,53.7455 -2.48894,53.7464 -2.48376,51.5126 -0.22443,51.5126 -0.22455,51.5129 -0.22522,51.5148 -0.22595,51.515 -0.22565,51.5152 -0.22007,51.5153 -0.21982,51.5153 -0.22207,51.516 -0.21593,51.5207 -0.16548,51.5274 -0.13044,51.5287 -0.1195,51.5294 -0.11581,51.5314 -0.114,51.5319 -0.10629,51.546 -0.10225,51.5468 -0.09851,51.5615 -0.09948,51.5618 -0.09859,51.5619 -0.09874,51.5621 -0.09774,51.5622 -0.09793,51.5629 -0.074843,51.5635 -0.07319,51.5638 -0.07423,51.5655 -0.07308,51.5065 -0.23453,51.5098 -0.2346,51.5125 -0.22443,51.5126 -0.22455,51.5141 -0.30077,51.3824 0.219232,51.3832 0.22189,51.3871 0.19381,51.3924 0.19631,51.4505 0.2384,51.4561 0.24682,51.4905 0.26753,51.6112 -0.13568,51.614 -0.1423,51.6149 -0.1279,51.6159 -0.0959,51.6166 -0.08625,51.6827 -0.04306,51.6827 -0.0485,50.8295 -0.135709,50.8336 -0.1389,51.0842 -0.20043,51.2584 -0.12584,51.4889 -0.49628,51.4928 -0.41087,51.493 -0.41909,51.5134 -0.40288,51.5158 -0.40192,51.5169 -0.41292,51.517 -0.41706,51.5171 -0.41794,51.5175 -0.41693,51.5189 -0.41131,51.506 -3.5765,51.5071 -3.57572,51.508 -3.57682,51.5089 -3.57687,51.5094 -3.57552,51.5268 -3.57319,51.5319 -3.57145,51.533 -3.567,51.5537 -2.54326,52.2083 -2.15995,52.2133 -2.15969,52.3653 -2.23896,52.3797 -2.25068,52.3856 -2.24433,52.3856 -2.24637,51.3017 0.14978,51.3168 -0.55901,51.317 -0.55852,51.3179 -0.5572,51.318 -0.55734,51.3714 -0.5076,51.3876 0.50573,51.3881 0.50679,51.3884 0.50491,51.3885 0.505716,51.3951 0.49271,51.3957 0.49308,51.3984 0.45032,51.3998 0.43212,51.423 0.2361,51.4259 0.23944,51.4269 0.24394,51.3017 0.14978,51.3168 -0.55901,51.317 -0.55852,51.3179 -0.5572,51.318 -0.55734,51.3714 -0.5076,51.3876 0.50573,51.3881 0.50679,51.3884 0.50491,51.3885 0.505716,51.3951 0.49271,51.3957 0.49308,51.3984 0.45032,51.3998 0.43212,51.423 0.2361,51.4259 0.23944,51.4269 0.24394,52.2027 0.13072,52.2027 0.13139,52.2041 0.12733,52.2048 0.12558,52.2052 0.124187,52.2083 0.13738,52.2139 0.1106,52.2139 0.1237,52.2146 0.12279,52.2163 0.13467,52.2332 0.07004,52.2374 0.06243,52.3776 -0.25321,52.5366 -0.3223,53.3912 -1.06914,53.5818 -1.21172,53.6173 -1.23025,53.809 -1.34127,54.1533 -1.43958,54.4485 -1.66852,54.7766 -1.57715,54.7777 -1.57547,54.7777 -1.57631,54.7906 -1.53038,54.7934 -1.52982
)' , 4326)
or
select geography::STGeomFromText( 'LINESTRING(
53.4707 -2.24758,53.4708 -2.25079,53.4733 -2.2597,53.4743 -2.24812,53.4747 -2.24119,53.4756 -2.26244,53.4765 -2.24278,53.4805 -2.28457,53.4909 -2.37892,53.5272 -2.36252,53.7159 -2.56899,53.7165 -2.56208,53.7183 -2.62195,53.7212 -2.55478,53.7439 -2.48239,53.7443 -2.48351,53.7446 -2.48767,53.7455 -2.48894,53.7464 -2.48376,51.5126 -0.22443,51.5126 -0.22455,51.5129 -0.22522,51.5148 -0.22595,51.515 -0.22565,51.5152 -0.22007,51.5153 -0.21982,51.5153 -0.22207,51.516 -0.21593,51.5207 -0.16548,51.5274 -0.13044,51.5287 -0.1195,51.5294 -0.11581,51.5314 -0.114,51.5319 -0.10629,51.546 -0.10225,51.5468 -0.09851,51.5615 -0.09948,51.5618 -0.09859,51.5619 -0.09874,51.5621 -0.09774,51.5622 -0.09793,51.5629 -0.074843,51.5635 -0.07319,51.5638 -0.07423,51.5655 -0.07308,51.5065 -0.23453,51.5098 -0.2346,51.5125 -0.22443,51.5126 -0.22455,51.5141 -0.30077,51.3824 0.219232,51.3832 0.22189,51.3871 0.19381,51.3924 0.19631,51.4505 0.2384,51.4561 0.24682,51.4905 0.26753,51.6112 -0.13568,51.614 -0.1423,51.6149 -0.1279,51.6159 -0.0959,51.6166 -0.08625,51.6827 -0.04306,51.6827 -0.0485,50.8295 -0.135709,50.8336 -0.1389,51.0842 -0.20043,51.2584 -0.12584,51.4889 -0.49628,51.4928 -0.41087,51.493 -0.41909,51.5134 -0.40288,51.5158 -0.40192,51.5169 -0.41292,51.517 -0.41706,51.5171 -0.41794,51.5175 -0.41693,51.5189 -0.41131,51.506 -3.5765,51.5071 -3.57572,51.508 -3.57682,51.5089 -3.57687,51.5094 -3.57552,51.5268 -3.57319,51.5319 -3.57145,51.533 -3.567,51.5537 -2.54326,52.2083 -2.15995,52.2133 -2.15969,52.3653 -2.23896,52.3797 -2.25068,52.3856 -2.24433,52.3856 -2.24637,51.3017 0.14978,51.3168 -0.55901,51.317 -0.55852,51.3179 -0.5572,51.318 -0.55734,51.3714 -0.5076,51.3876 0.50573,51.3881 0.50679,51.3884 0.50491,51.3885 0.505716,51.3951 0.49271,51.3957 0.49308,51.3984 0.45032,51.3998 0.43212,51.423 0.2361,51.4259 0.23944,51.4269 0.24394,51.3017 0.14978,51.3168 -0.55901,51.317 -0.55852,51.3179 -0.5572,51.318 -0.55734,51.3714 -0.5076,51.3876 0.50573,51.3881 0.50679,51.3884 0.50491,51.3885 0.505716,51.3951 0.49271,51.3957 0.49308,51.3984 0.45032,51.3998 0.43212,51.423 0.2361,51.4259 0.23944,51.4269 0.24394,52.2027 0.13072,52.2027 0.13139,52.2041 0.12733,52.2048 0.12558,52.2052 0.124187,52.2083 0.13738,52.2139 0.1106,52.2139 0.1237,52.2146 0.12279,52.2163 0.13467,52.2332 0.07004,52.2374 0.06243,52.3776 -0.25321,52.5366 -0.3223,53.3912 -1.06914,53.5818 -1.21172,53.6173 -1.23025,53.809 -1.34127,54.1533 -1.43958,54.4485 -1.66852,54.7766 -1.57715,54.7777 -1.57547,54.7777 -1.57631,54.7906 -1.53038,54.7934 -1.52982,53.3615 -2.2943,53.3616 -2.29438,53.3619 -2.29431,53.3626 -2.29606,53.363 -2.29748,53.3683 -2.31356,53.3687 -2.31296,53.3967 -2.26766,53.3984 -2.22994,53.481 -2.05105,53.4821 -2.05214,53.4821 -2.11473,53.4827 -2.10573,53.4828 -2.05008,53.4858 -2.05878,53.7633 -2.70157,53.7636 -2.70038,53.7672 -2.70313,53.7952 -2.98557,53.8002 -2.72228,53.8011 -2.71739,53.804 -3.02696,53.8139 -3.05028,53.815 -3.04473,53.8163 -3.05226,53.4707 -2.24758,53.4708 -2.25079,53.4733 -2.2597,53.4743 -2.24812,53.4747 -2.24119,53.4756 -2.26244,53.4765 -2.24278,53.4805 -2.28457,53.4909 -2.37892,53.5272 -2.36252,53.7364 -2.64886,53.7952 -2.98557,53.804 -3.02696,53.806 -2.70331,53.8139 -3.05028,53.815 -3.04473,53.8163 -3.05226,51.401 -0.5297,51.4052 -0.34152,51.4111 -0.300524,51.4126 -0.30176,51.4164 -0.42419,51.4191 -0.41833,51.7152 -0.3928,52.8399 -1.29605,52.8429 -1.29658,52.9216 -1.16451,52.9265 -1.16722,52.9488 -1.1511,52.9489 -1.15012,52.9493 -1.14992,52.9504 -1.14983,52.9509 -1.15128,52.9513 -1.1503,52.9514 -1.15141,52.9517 -1.15273,52.9521 -1.15199,51.502 -0.15932,51.5024 -0.1555,51.5033 -0.14984,51.5033 -0.15075,51.5042 -0.1511,51.5132 -0.16003,51.5134 -0.15871,51.5227 -0.17393,51.5685 -0.2291,51.5712 -0.23129,51.5719 -0.22982,51.573 -0.228,51.5731 -0.22961,51.5763 -0.23571,52.3953 -1.17295,52.6728 -2.07963,53.4061 -2.8963,53.407 -2.90128,53.4075 -2.90136,53.4078 -2.97954,53.4078 -2.9802,53.4078 -2.98228,53.408 -2.98106,53.41 -2.97854,53.4103 -2.90155,53.4103 -2.97767,53.4112 -2.97723,53.4133 -2.96398,53.4143 -2.96216,53.4237 -2.57435,53.4273 -2.91804,51.5033 -0.149834,51.5042 -0.1511,51.5044 -0.14749,51.5051 -0.15035,51.5051 -0.15089,51.5052 -0.15032,51.5056 -0.14872,51.5126 -0.15886,51.5132 -0.1607,51.5179 -0.16725,51.5226 -0.17378,51.5685 -0.22934,51.5686 -0.22953,51.5709 -0.23185,51.5719 -0.23053,52.4003 -1.17515,52.4768 -1.68081,52.6655 -2.06869,53.4062 -2.95647,53.4064 -2.89868,53.4064 -2.95565,53.407 -2.95622,53.4072 -2.95609,53.4075 -2.97961,53.4076 -2.98199,53.4076 -2.98408,53.4084 -2.97404,53.4087 -2.97886,53.4087 -2.98279,53.4092 -2.97452,53.4098 -2.91679,53.4213 -2.54907,51.4871 0.2647,51.4878 0.26815,51.4901 0.26826,51.4931 0.26921,51.4986 0.26975,51.4988 0.25643,51.499 0.25929,51.5001 0.25941,51.5002 0.25852,51.5019 0.26817,51.6053 0.26623,51.6087 0.26389,51.6108 0.26624,51.8917 0.8989,51.8918 0.89627,51.8918 0.89984,51.8919 0.89838,51.892 0.900363,51.8924 0.89627,51.8926 0.86479,51.8926 0.89413,51.8926 0.89605,51.8953 0.8574,51.8966 0.89092,51.5042 -0.08496,51.5051 -0.0844,51.5061 -0.08801,51.5063 -0.08826,51.5108 -0.08656,51.5114 -0.07264,51.5115 -0.07297,51.5119 -0.06908,51.5138 -0.07593,51.5152 -0.07174,51.5161 -0.08162,51.5266 -0.02797,51.5288 -0.01608,51.53 -0.01417,51.5311 -0.01715,51.5927 0.21329,51.5929 0.20981,51.8917 0.8989,51.8918 0.89627,51.8918 0.89984,51.8919 0.89838,51.892 0.900363,51.8924 0.89627,51.8926 0.86479,51.8926 0.89413,51.8926 0.89605,51.8953 0.8574,51.8966 0.89092
)' , 4326)
I have many similar queries than run just fine.
Can anyone tell me why these particular ones fail? I'm at a loss.
Thanks in advance.
I cannot see this from your data, but it seems that you are running into this problem: The LineString instance cannot overlap itself over an interval.
It might be useful for you to use the MakeValid() function to correct this.
It was indeed the line overlapping itself.
I managed to create a valid geography object using
http://sqlspatialtools.codeplex.com/
Great article here:
http://blogs.msdn.com/b/edkatibah/archive/2009/06/05/working-with-invalid-data-and-the-sql-server-2008-geography-data-type-part-2.aspx