I am dealing with a database that has column with spaces. So I try to enclose the Column in brackets like this...
#Column(name = "[Licensee Address]")
However when I run the app. Hibernate replaces Brackets with this
`Licensee Address`
Which throws a error
Incorrect syntax near '`'.
MSSQL uses brackets not quotes. How do I fix this ??
When I do it without the brackets it generates the following sql...
Hibernate: select licenseein0_.WRRAppID as WRRAppID1_1_0_, licenseein0_.ApplicantTypeID as Applican2_1_0_, licenseein0_.BusinessActivity as Business3_1_0_, licenseein0_.CompanyID as CompanyI4_1_0_, licenseein0_.CreatedBy as CreatedB5_1_0_, licenseein0_.CreatedDate as CreatedD6_1_0_, licenseein0_.DBAName as DBAName7_1_0_, licenseein0_.FCCCallSign as FCCCallS8_1_0_, licenseein0_.FCCFileNumber as FCCFileN9_1_0_, licenseein0_.FCCRegistration# as FCCRegi10_1_0_, licenseein0_.FedTaxID# as FedTaxI11_1_0_, licenseein0_.LicenseActionID as License12_1_0_, licenseein0_.LicenseeName as License13_1_0_, licenseein0_.RadioService as RadioSe14_1_0_, licenseein0_.RadioUse as RadioUs15_1_0_, licenseein0_.SubmittedDate as Submitt16_1_0_ from Licensee_Information licenseein0_ where licenseein0_.WRRAppID=?
And the error message I get is...
Incorrect syntax near the keyword 'as'.
Figured it out. Had to incorrect hibernate dialect set up. It must be the following
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect
The column name isn't [Licensee Address], the column name is Licensee Address. If you remove the [ and ] it should work. If you are writing a query in T-SQL and you need to reference a column named with a space, special characters or reserved words, you need to put the [ and ] so the query parser knows where the column name starts and stops. But you are not writing T-SQL, so you don't need to do that.
Related
I'm trying to issue an update ExecuteStatementRequest using DynamoDB and Java SDK 2.0. I'm struggling to escape keywords that are columns in my table schema.
The following statement:
var response = client.executeStatement(ExecuteStatementRequest.builder()
.statement("""
UPDATE "my-table"
SET value=12.5
WHERE assignmentId='item1#123#item2#456#item3#789'
RETURNING ALL NEW *
""")
.build());
When I run the following statement (notice that value column is a reserved keyword) I get the following error:
Exception in thread "main"
software.amazon.awssdk.services.dynamodb.model.DynamoDbException:
Statement wasn't well formed, can't be processed: Expected identifier
for simple path (Service: DynamoDb, Status Code: 400, Request ID: XXX)
If instead of value I change the column name to val, the statement works fine. I know that in UdateItem operations I can pass in an array of expressionAttributeNames to replace keywords with aliases. Is there a similar primitive I can use for ExecuteStatementRequest?
The documentation you link explicitly says what you need to do:
You can use a reserved keyword as a quoted identifier with double
quotation marks (for example, "user").
That is the SQL standard way of escaping reserved words. In other words, use "value" (or possibly "VALUE") in your statement instead of value.
I'm getting below error while executing the following query using JPA native query
Error :
ERROR: operator does not exist: record = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 228
Query:
select ar.adm_rule_id
from adm_promo.adm_rule ar,
adm_promo.adm_non_comp_rule ac,
adm_promo.adm_rule_hier_level ah
where ar.rule_type =?
and ar.sales_org_id=?
and (ac.promo_market_id,ah.level_id) in (?)
and ar.adm_rule_id=ac.adm_rule_id
and ar.adm_rule_id=ah.adm_rule_id
and ar.delete_f='N'
and (ar.eff_end_date>=(?) and ar.eff_start_date<=(?))
and ar.dist_channel=?
But I'm getting result for the same query with actual inputs, when I tried in PostgreSql
Query with inputs:
select ar.adm_rule_id
from adm_promo.adm_rule ar,
adm_promo.adm_non_comp_rule ac,
adm_promo.adm_rule_hier_level ah
where ar.rule_type =1
and ar.sales_org_id=1
and (ac.promo_market_id,ah.level_id) in ((9,63))
and ar.adm_rule_id=ac.adm_rule_id
and ar.adm_rule_id=ah.adm_rule_id
and ar.delete_f='N'
and (ar.eff_end_date>=('2020-09-29')
and ar.eff_start_date<=('2020-10-17'))
and ar.dist_channel=1
I couldn't find the issue exactly, team please help me to resolve this issue.
I suspect it has a problem with this:
(ac.promo_market_id,ah.level_id) in (?)
Try to cast it, as suggested in the error, by changing the query to:
(ac.promo_market_id,ah.level_id) in (?::record)
Judging by the fact that it says "position 228" and scrolling along to that character of your query puts you near this:
(ac.promo_market_id,ah.level_id) in ((9,63))
but your template for the query has this
(ac.promo_market_id,ah.level_id) in (?)
It might well be that you are providing the wrong sort of data there. It is unlikely that your database driver supports parameterized lists of values (to match your "IN" clause). You are probably ending up with some quoted text, which Postgres is treating as "character varying" which of course fails to match.
I figured out that of course . and SPACE aren't allowed. Are there other forbidden characters ?
You can use any (UTF8) character in the field name which aren't
special (contains ".", or starts with "$").
https://jira.mongodb.org/browse/SERVER-3229
https://stackoverflow.com/a/7976235/311220
It's generally best to stick with lowercase alphanumeric with underscores though.
Something else to look out for is the fact that you can make a property name called "query" but then use query operators on it, making it awkward to do a large number of queries.
Example:
Insert document with a property named
db.coll.insert({ query: 'foo' });
Equality query works:
db.coll.findOne({ query: 'foo' });
Not equal ($ne) does not:
db.coll.findOne({ query: { $ne: 'bar' } });
I'm using the statement below to update/insert some data to a table and, if I run it without parameters, it's fine. However, as soon as I try to execute it using parameters it throws:
SQL0418N - A statement contains a use of an untyped parameter marker, the DEFAULT keyword, or a null value that is not valid.
I've read the error information here, but I'm still struggling with why my statement won't execute.
--This statement works
MERGE Into AB.Testing_Table A
USING (VALUES('TEST', 'P')) B(TEST_ID, "ACTION")
ON (A.TEST_ID = B.TEST_ID)
WHEN NOT MATCHED THEN
INSERT (TEST_ID, "ACTION")
VALUES ('TEST', 'P')
WHEN MATCHED THEN
UPDATE SET TEST_ID = 'TEST'
,"ACTION" = 'P';
--This statement fails with error SQL0418N
MERGE Into AB.Testing_Table A
USING (VALUES(#TEST, #ACTION)) B(TEST_ID, "ACTION")
ON (A.TEST_ID = B.TEST_ID)
WHEN NOT MATCHED THEN
INSERT (TEST_ID, "ACTION")
VALUES (#TEST, #ACTION)
WHEN MATCHED THEN
UPDATE SET TEST_ID = #Test
,"ACTION" = #Action;
Thanks in advance for the help!
Basically, DB2 doesn't know what data types you're sending in on those parameters. I'm guessing you're either on an older version of DB2 (less than 9.7 on Linux/Unix/Windows, or on a Mainframe version older than 10.1), which doesn't do a whole lot of "automatic" type conversion. Or you're sending in NULL values (which still have to be "typed", strange as it sounds).
You can fix the problem by creating your parameter markers as typed parameters (I'm assuming data types here, use what would be appropriate):
MERGE INTO AB.TESTING_TABLE A
USING (VALUES (
CAST(#TEST AS CHAR(4))
,CAST(#ACTION AS CHAR(1))
)) B(TEST_ID, "ACTION")
ON (A.TEST_ID = B.TEST_ID)
WHEN NOT MATCHED THEN
INSERT (TEST_ID, "ACTION")
VALUES (B.TEST_ID, B.ACTION)
WHEN MATCHED THEN
UPDATE SET "ACTION" = B.ACTION
Additionally, since you're using the MERGE, you don't have to use parameters in the UPDATE or INSERT parts, you can refer to the values in the USING table you passed in. Also, since you're matching on TEST_ID, you don't need to include that in your UPDATE statement, since it wouldn't be updated, anyway.
I have just started using MySQL today, so please without hate.
This is the table how it looks in phpmyadmin: http://i.imgur.com/B6wg9qG.png
Here is the method I'm using: http://i.imgur.com/BZWhZw9.png
Here is the error I'm getting: "Bad format for number 'gold' in column 1.", it's pointing on this line: return st.getDouble(1);
Thanks for any help!
You're doing
SELECT 'gold' FROM `Economy` WHERE...
That will select the string literal 'gold' from the database, not the value of the gold field.
If you want to quote a field name, you need to use backticks;
SELECT `gold` FROM `Economy` WHERE...
...although the query in this case will work just as well without quoting the field name at all.