Cassandra counter type in User defined type - database

I have a type and a table
CREATE TYPE IF NOT EXISTS info(
street text,
c_counter counter
);
CREATE TABLE customer (
id UUID PRIMARY KEY,
customer_info info
);
which's way to use the counter on customer table within the UDT?
I tried with this
UPDATE customer SET customer_info.c_counter = customer_info.c_counter + 1 WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
and I got the error:
SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line xxx no viable alternative at input '+' (...customer SET customer_info.c_counter = [customer_info].c_counter...)">
Thank you so much guys.

Related

What tables hold the job category class and types?

In SQL Server.
In the table msdb.dbo.syscategories how do I get the value for the ids category_class and category_type name
i.e: class 1 = JOB
type 1 = LOCAL
You get it from the docs:
Column name
Data type
Description
category_id
int
ID of the category
category_class
int
Type of item in the category:
1 = Job
2 = Alert
3 = Operator
category_type
tinyint
Type of category:
1 = Local
2 = Multiserver
3 = None
name
sysname
Name of the category
The system catalog views typically don't have "lookup tables" for each of these.

Oracle Spatial search query error for SDO_WITHIN_DISTANCE (lat/long based)

I need to perform location based search based on latitude and longitude pairs, to find out the near by locations of stores within a radius/distance of given KMs.
I am to use (for certain) Oracle's SDO_GEOMETRY for searching the locations.
Also, the table structure are parent-child based such that store address (zip, lat/long) is in parent table but store details (name, contact, etc) are in the child table.
This is to make sure that we do not have redundant data (as multiple store can have same lat/long and by some dark magic same address)
I have the following scenario (tables provided):
Version - Oracle Database 12c Enterprise Edition Release 12.2.0.1.0
Table: STORE_LOCATION
CREATE TABLE STORE_LOCATE
(
ID NUMBER DEFAULT STORE_LOCATE.nextval,
POSTAL_CODE VARCHAR2(18) NOT NULL,
ADDRESS VARCHAR2(382) NOT NULL,
GEO_LOCATION SDO_GEOMETRY NOT NULL
);
Table: STORE_DETAIL
CREATE TABLE STORE_DETAIL
(
ID NUMBER DEFAULT STORE_DETAIL_SEQ.nextval,
STORE_CODE VARCHAR2(20) NOT NULL,
STORE_NAME VARCHAR2(150) NOT NULL,
IS_ACTIVE NUMBER(3) DEFAULT 0 NOT NULL,
fk_store_locate_id INT NOT NULL. -- FK to ID of parent
);
I have inserted data in parent as:
INSERT INTO STORE_LOCATE (ZIP, ADDRESS, GEO_LOCATION) VALUES
('567875', '84 Paddar Road',
SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE (80.34234431,26.12354422, NULL), NULL, NULL));
Likewise, child table has entries:
INSERT INTO STORE_DETAIL (STORE_CODE, STORE_NAME, FK_STORE_LOCATION_ID) VALUES
('ST01', 'STORE 1', 1);
So, now when a user shares his location to me (lat/long), I need to search all nearby locations of stores within a specified radius.
I tried the following query, but I am getting error with this:
SELECT
s.store_code,
s.store_name,
loc.zip,
loc.address,
loc.geo_location
FROM store_detail s,
store_locate loc
where MDSYS.SDO_WITHIN_DISTANCE(loc.geo_location,
(MDSYS.SDO_GEOMETRY(2001, 8307,
MDSYS.SDO_POINT_TYPE(80.21456732,26.23117864, NULL) ,NULL, NULL)),
'distance=1000 unit=KM') = 'TRUE';
Getting the below error:
ORA-29900: operator binding does not exist
ORA-06553: PLS-306: wrong number or types of arguments in call to 'SDO_WITHIN_DISTANCE'
29900. 00000 - "operator binding does not exist"
*Cause: There is no binding for the current usage of the operator.
*Action: Change the operator arguments to match any of the existing
bindings or add a new binding to the operator.
I am breaking my head around this for a while now but in vain.
Ref:
https://issues.redhat.com/browse/TEIID-751?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
https://docs.oracle.com/cd/E17781_01/appdev.112/e18750/xe_locator.htm#XELOC562
Q's:
Is this the correct way to perform location search on Oracle SQL?
Is there any other way if the above is incorrect?
There are a number of syntax errors in your code (POSTAL_CODE called ZIP, etc)
Here is the corrected example (I also removed the sequences for simplicity)
CREATE TABLE STORE_LOCATE (
ID NUMBER primary key,
POSTAL_CODE VARCHAR2(18) NOT NULL,
ADDRESS VARCHAR2(382) NOT NULL,
GEO_LOCATION SDO_GEOMETRY NOT NULL
);
CREATE TABLE STORE_DETAIL (
ID NUMBER primary key,
STORE_CODE VARCHAR2(20) NOT NULL,
STORE_NAME VARCHAR2(150) NOT NULL,
IS_ACTIVE NUMBER(3) DEFAULT 0 NOT NULL,
fk_store_locate_id INT NOT NULL references STORE_LOCATE
);
INSERT INTO STORE_LOCATE (ID, POSTAL_CODE, ADDRESS, GEO_LOCATION) VALUES (1, '567875', '84 Paddar Road', SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE (80.34234431,26.12354422, NULL), NULL, NULL));
INSERT INTO STORE_DETAIL (ID, STORE_CODE, STORE_NAME, FK_STORE_LOCATE_ID) VALUES (1001,'ST01', 'STORE 1', 1);
commit;
Here is running your query:
SELECT
s.store_code,
s.store_name,
loc.postal_code,
loc.address,
loc.geo_location
FROM store_detail s, store_locate loc
where SDO_WITHIN_DISTANCE(
loc.geo_location,
SDO_GEOMETRY(2001, 8307,
SDO_POINT_TYPE(80.21456732,26.23117864, NULL),NULL, NULL
),
'distance=1000 unit=KM'
) = 'TRUE';
STORE_ STORE_NAME POSTAL ADDRESS GEO_LOCATION(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES
------ ---------- ------ -------------------- ----------------------------------------------------------------------------------
ST01 STORE 1 567875 84 Paddar Road SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(80.3423443, 26.1235442, NULL), NULL, NULL)
1 row selected.
The error you get probably means Oracle Spatial is not or incorrectly installed in your database. What exact database version do you use ?
IMPORTANT NOTE:
Those queries really need a spatial index on the GEO_LOCATION column. Without one, the query is rejected in versions up to 12.1. From 12.2 and later, the query will run, but will be very slow as soon as the number of locations goes above a few 100s. Once you go into the 100000 or more, it will be very slow.
See https://docs.oracle.com/en/database/oracle/oracle-database/19/spatl/indexing-querying-spatial-data.html#GUID-07129836-0DAE-4BCC-B290-942C456AE2EA for details

How do I select column value based on other column

Hi Right now I am using this code in my MVC project :
AppHistory history = new AppHistory();
history = (from AppHistory app in Market.AppHistories
where app.HistoryID == 11
select app).ToList().FirstOrDefault();
Here I am passing value for app.historyID as 11. In my SQL, this is primary key identity specification. I have userID which I am storing for current users.
So what i should do is instead of passing hardocoded value to app.HistoryID, i need to pass userID parameter here and have to select app.HistoryID based on that userID.
How can i do this?
Update :
My table design is shown below. I was not able to upload snap so I am writing my design below:
ColumnName DataType AllowNulls
HistoryID(Primary key) int No
userUID int Yes
HistoryUserActive int yes
HistoryInactiveFrom int yes
HistoryStart datetime yes
HistoryMonthCost int yes
Update 2:
Can i do like this to check column name based on userID :
int userId = userID
history = (from AppHistory app in termsAccepted.AppHistories
where app.UserID == userId
select app).FirstOrDefault();
Now I need to check whether user has historyID, that is hitory.historyID. For this i need to write if condition like :
if (history.historyID exists)
{
//
}
Here what code i should write to check historyID exists or not?

How to convert an anorm resultlist from a two-field data table to a Tuple2, in Scala

I have the following table (maximum number of records 999) I use for a lookup:
CREATE TABLE lga
(
lgacode character varying(3) NOT NULL DEFAULT '000'::character varying,
lganame character varying(32) NOT NULL,
CONSTRAINT pk_lga PRIMARY KEY (lganame),
CONSTRAINT uk_lga UNIQUE (lgacode)
);
Using Anorm, I easily get a result list lgas of the type List[models.LgaTable]
How do I get this result list into the form List[Tuple2[String,String]]?
I searched Stack Overflow and found something close ([a link]http://stackoverflow.com/questions/4927260/filling-a-scala-immutable-map-from-a-database-table) but this contained Set, which I have an aversion for, meanwhile: I just needed something simple. Thanks
Just call a map on your result:
val lgas: List[models.LgaTable] = ...
val lgas_tupled = lags.map(row => (row.lgacode, lganame))

Oracle null and unique constraint

Does a unique constraint include a not null constraint?
I have a case that one attribute cellPhone can be NULL but cannot be repeated, so I give it 2 constraints: "not null" and "unique", in a case of updating the record, if user didn't enter a value I put 0 in the field, so it makes this exception:
SEVERE: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (TEST1.OSQS_PARENTS_CELLPHONE_UK) violated
What should I do in the UPDATE case?
EDIT
here's the definition of table ddl
CREATE TABLE "TEST1"."OSQS_PARENTS"
( "PARENT_NO" NUMBER(38,0),
"PARENT_NAME" VARCHAR2(4000 BYTE),
"PARENT_ID" NUMBER(38,0),
"PARENT_EMAIL" VARCHAR2(30 BYTE),
"PARENT_CELLPHONE" NUMBER(38,0)
)
and here's an image of the constraints
and here is the update statement
Parent aParent; //is an object I pass through a function
String SQlUpdate = "UPDATE OSQS_PARENTS P SET P.PARENT_ID=?,P.PARENT_EMAIL=?,P.PARENT_CELLPHONE=?"
+ " where P.PARENT_NO=?";
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(SQlUpdate);
pstmt.setLong(1, aParent.getId());
pstmt.setString(2, aParent.getEmail());
pstmt.setLong(3, aParent.getCellPhoneNo());
pstmt.setLong(4, parentNo);
pstmt.executeUpdate();
}
it sounds like this:
cellPhone must be unique. When user does not input value, you mark it as a 0. Thus it fails when you try to insert multiple 0 values into a 'UNIQUE' column.
I believe you need to drop the NOT NULL constraint on the column (allow it to be UNIQUE yes, but allow NULLS).
Then when user inputs no value, use it as a NO value (unknown = null <> 0 -- 0 is a known value )
throw an IF into your statement, if value then what you have, otherwise SET IT TO NULL!\
pstmt.setNull(3, java.sql.Types.INTEGER);

Resources