column "st_srid" does not exist - java

Hi I'm executing this query in my java code and it tells me
org.postgresql.util.PSQLException: ERROR: column "st_srid" does not exist
However when I run it directly in pgAdmin it shows me the column and the value inside.
Here is my query:
"Select Distinct ST_SRID(shape) from TableName where shape IN (SELECT shape from TableName)"
I appreciate any help

Distinct needs parenthesis around the st_srid function call.

Related

in #Query , I need to query DB to select a row where a column is null. I am using JpaRepository

I have tried using below query
#Query(value = "select E.SRC,E.TRGT,E.EVNT_STTS,E.ADDL_ATTR from EVNT.EVNT_LOG E where E.EVNT_ID=:eventId and E.ADDL_ATTR IS NULL" , nativeQuery = true)
List<AggregationLog> findByEventIdAndTargetAndAdditionalAttributeWithNULL(#Param("eventId") Long eventId);
in above query I am getting invalid column name.
Please guide me to select a row with eventID and addl_attr as null.
Well... invalid column means oracle cannot resolve the column name in the query. That usually means 1 of 2 things:
A Typo
The columns were created with case sensitivity. Whoever created the table surrounded the column names with double quotes and put column names in something other than all caps. Do a "DESCRIBE <table_name>" in sqlplus, sqldeveloper or any other client and check if the column names are all upper case. If they're not, you will need to enclose them in double quotes in your query with the name matching exactly what you see.

how to include serial number to query result with spring jpa native query?

I have tried this query:
SELECT #rownumber:=#rownumber+1 as rownumber, column From Table, (SELECT #rownumber:=0) D
in my workbench and it works but it does work in spring data jpa. I get this error instead:
Caused by: org.hibernate.QueryException: Not all named parameters have been set: [0, #rownumber]
I have tried switching the postion of the colon like this #rownumber=:#rownumber+1 and #rownumber=:0
What could be the problem with the query? Is there a way to correct it or is there proven way to include serial number in my query result?
Try to escape the : char and use \\:
SELECT #rownumber\\:=#rownumber+1 as rownumber, column
From Table, (SELECT #rownumber\\:=0) D

Merge and When Matched query giving an error sql server

I have a query which I am trying to test. The query should update the data if it finds data in the table with existing primary key. If it doesn't then insert into the table.
The Primary key is of type int and in the properties I can see Identity is set to "True" which I assume it means that it will automatically set the new id for the primary if it is inserted.
MERGE INTO Test_table t
USING (SELECT 461232 ID,'Test1-data' Fascia FROM Test_table) s
ON (t.ID = s.ID)
WHEN MATCHED THEN
UPDATE SET t.Fascia = s.Fascia
WHEN NOT MATCHED THEN
INSERT (Fascia)
VALUES (s.Fascia);
The issue here is this query doesn't work and it never inserts the data or updates. Also, query gets compiled and I don't get any compilation error
Also the reason I want this query is to work because then I will use Java prepared statement to query the database so I am assuming I can do
SELECT ? ID,? Fascia FROM Test_table
So that I can pass the values with set methods in java.
Please let me know if there is something wrong in my query.
You are selecting from the target table as your source.
You either need to remove your FROM Test_table or have at least 1 row in Test_table prior to your merge.
rextester demo: http://rextester.com/XROJD28508
MERGE INTO Test_table t
USING (SELECT 461232 ID,'Test1-data' Fascia --FROM Test_table
) s
ON (t.ID = s.ID)
WHEN MATCHED THEN
UPDATE SET t.Fascia = s.Fascia
WHEN NOT MATCHED THEN
INSERT (Fascia)
VALUES (s.Fascia);

"Invalid Column id" error when counting unique value in Java

I am using the following sql query in my java program:
SELECT COUNT(*) FROM event WHERE externaleventid ='1256294';
But I have an error as:
Invalid Column id.
Same query works fine in SQL Developer.
For some reason you are attempting to get a column named "externaleventid" from the query, but only "count(*)" is available. You shouldn't try to get back the where clause bind variables from the result set, you should get the actual data back from the result set, by column index or by column name.
Try rs.getInt(1) to get the data from the first column. Or, you can alias the column in the query, e.g. SELECT count(*) cnt FROM..., and you can refer to it by the aliased column name: rs.getInt("cnt").

Insert into statement with parentheses in column names

I am use Java to insert into a MSSQL database. I have column names with parentheses in them like Duration_(Mins).
I am trying to execute a statement like:
INSERT INTO mytable (Duration_(Mins)) VALUES (?)
and I am getting the following error:
Exception in thread "main" java.sql.SQLException: Incorrect syntax near '('
So I am guessing I need some way to "escape" the bracket?
For MS-SQL Server, this should work:
INSERT INTO mytable ([Duration_(Mins)]) VALUES (?)
For details, refer this link:
http://msdn.microsoft.com/en-us/library/ms132046.aspx#DelimitedIdentifiers

Categories

Resources