Create a table statement as follows:
[omm#tpl-centos7 bin]$ ./gsql -ddev -Uomm -p26000 -f test.sql
gsql:test.sql:7: ERROR: column name “tid” conflicts with a system column name
total time: 0 ms
[omm#tpl-centos7 bin]$ cat test.sql
CREATE TABLE if not exists ax_quarantine_rcpt
(
“tid” varchar2(255) NOT NULL,
rcpt varchar2(255) NOT NULL,
org_id varchar2(60) NOT NULL,
PRIMARY KEY (“tid”,rcpt)
);
error:column name “tid” conflicts with a system column name
Looking at the documentation, it says reserved words must never be used as other identifiers, but tid is also not in the keyword
Referring to the Internet with double quotation marks does not work, solve
It may be a version problem. He described that the tid is occupied by the system view field. I can use the latest compiled version. It is recommended to use the latest version.
If you cannot compile it yourself, you can use the container version. https://hub.docker.com/repository/docker/enmotech/opengauss
I have an issue retrieving an object with the DEREF word. I am sure it is a simple answer, I just haven't been able to get my head around what I'm doing wrong. My database is as follows:
I have the following types in a database of Students and their respective academic marks:
create or replace NONEDITIONABLE TYPE TSUBJECT AS OBJECT
(
codeSubject NUMBER,
name VARCHAR2(20)
)
and the above object type for academic subjects is referenced in the following object type, which stores marks and references a particular TSUBJECT object type:
create or replace NONEDITIONABLE TYPE TMARKS OBJECT
(
lineNumber number,
codeSubject ref TSUBJECT,
marksArray TMARKSARRAY -- JUST AN ARRAY OF ACADEMIC MARKS
)
and I have a table which is made of TMARKS object types, which will be nested in the Students table as a field called nestedTable.
create or replace NONEDITIONABLE TYPE MARKS_TABLE
AS TABLE OF TMARKS;
The Students table is a regular table of students' personal details, the only important field now is the last field of the table which is the nestedTable of type MARKS_TABLE :
The procedure:
create or replace NONEDITIONABLE PROCEDURE showStudentMarks(idStudent VARCHAR2) AS
nestedT Students.nestedTable%type;
marks TMARKS:= TMARKS(NULL,NULL,NULL);
subject TSUBJECT:= TSUBJECT(NULL,NULL,NULL);
BEGIN
select nestedTable into nestedT from Students where ID=idStudent;
For i in 1..nestedT .count
loop
marks:=nestedT(i);
-- subject:=deref(marks.codeSubject); DOESNT WORK !
dbms_output.put_line('Number of Line: ' || marks.lineNumber); -- WORKS FINE
dbms_output.put_line('First Mark for subject xx: ' || marks.marksArray(1)); -- WORKS FINE
End loop;
NULL;
END showStudentMarks;
Basically retrieving marks.lineNumber works, retrieving marks.marksArray(1) works, but deref(marks.codeSubject) doesn't, and I need to obtain the name of the subject from the TSUBJECT object type, supossedly by dereferencing it using deref(marks.codeSubject).name but it doesn't seem to work or most probably I am using the wrong syntax for it. Thanks
You haven't stated a version of Oracle, nor have you provided a complete definition of the problem, and what you have posted doesn't compile. Where, for example is the DDL for the STUDENT and SUBJECT table(s) and the TMARKSARRAY type?
Anyway, unfortunately DEREF doesn't work exactly the same in PL/SQL (see docs) you probably just want...
SELECT DEREF (marks.codesubject)
INTO subject
FROM DUAL;
Note though that (although object-relational features are rarely used) it is generally considered a good idea to use SQL to traverse object-relational schemas as far as possible, the syntax is arguably richer and the optimizer has more flexibility in how it accesses the data. A similar traversal in SQL might resemble the below...
SELECT s.id student#,
nt.linenumber mark#,
DEREF (nt.codesubject).codesubject subject#,
DEREF (nt.codesubject).name subject_name,
m.COLUMN_VALUE mark
FROM students s,
TABLE (s.nestedtable) nt,
TABLE (nt.marksarray) m
WHERE s.id = 1;
One really neat feature of Postgres that I have only just discovered is the ability to define composite type - also referred to in their docs as ROWS and as RECORDS. Consider the following example
CREATE TYPE dow_id AS
(
tslot smallint,
day smallint
);
Now consider the following tables
CREATE SEQUENCE test_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1;
CREATE TABLE test_simple_array
(
id integer DEFAULT nextval('test_id_seq') NOT NULL,
dx integer []
);
CREATE TABLE test_composite_simple
(
id integer DEFAULT nextval('test_id_seq') NOT NULL,
dx dow_id
);
CREATE TABLE test_composite_array
(
id integer DEFAULT nextval('test_id_seq') NOT NULL,
dx dow_id[]
);
CRUD operations on the first two tables are relatively straightforward. For example
INSERT INTO test_simple_array (dx) VALUES ('{1,1}');
INSERT INTO test_composite_simple (dx) VALUES (ROW(1,1));
However, I have not been able to figure out how to perform CRUD ops when the table has an array of records/composite types as in test_composite_array. I have tried
INSERT INTO test_composite_array (dx) VALUES(ARRAY(ROW(1,1),ROW(1,2)));
which fails with the message
ERROR: syntax error at or near "ROW"
and
INSERT INTO test_composite_array (dx) VALUES("{(1,1),(1,2)}");
which fails with the message
ERROR: column "{(1,1),(1,2)}" does not exist
and
INSERT INTO test_composite_array (dx) VALUES('{"(1,1)","(1,2)"}');
which appears to work though it leaves me feeling confused since a subsequent
SELECT dx FROM test_composite_array
returns what appears to be a string result {"(1,1),(1,2)} although a further query such as
SELECT id FROM test_composite_array WHERE (dx[1]).tslot = 1;
works. I also tried the following
SELECT (dx[1]).day FROM test_composite_array;
UPDATE test_composite_array SET dx[1].day = 99 WHERE (dx[1]).tslot = 1;
SELECT (dx[1]).day FROM test_composite_array;
which works while
UPDATE test_composite_array SET (dx[1]).day = 99 WHERE (dx[1]).tslot = 1;
fails. I find that I am figuring out how to manipulate arrays of records/composite types in Postgres by trial and error and - altough Postgres documentation is generally excellent - there appears to be no clear discussion of this topic in the documentation. I'd be much obliged to anyone who can point me to an authoritative discussion of how to manipulate arrays of composite types in Postgres.
That apart are there any unexpected gotchas when working with such arrays?
You need square brackets with ARRAY:
ARRAY[ROW(1,1)::dow_id,ROW(1,2)::dow_id]
A warning: composite types are a great feature, but you will make your life harder if you overuse them. As soon as you want to use elements of a composite type in WHERE or JOIN conditions, you are doing something wrong, and you are going to suffer. There are good reasons for normalizing relational data.
I downloaded the Wikipedia Pagelinks dataset (available on Wiki Dumps - http://dumps.wikimedia.org/enwiki/20140102/). I want to run PageRank algorithm on the dataset, however, I am unable to parse the data because it is not very well documented.
This is a sample of the dataset downloaded. The fields given are p1_from, p1_namespace, and p1_title. Looking online, p1_namespace is a number that denotes the type of article, but I do not know what p1_from is. To implement the pagerank algorithm, I want the number of articles that link to a particular article, however, I do not know what p1_from stands for. By its name, it sounds like it is the number of links that go away from that article, and not the other way around. Is this the case? And also, if it is, how can I reverse the graph given the data, so I can find the correct numbers.
DROP TABLE IF EXISTS `pagelinks`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pagelinks` (
`pl_from` int(8) unsigned NOT NULL DEFAULT '0',
`pl_namespace` int(11) NOT NULL DEFAULT '0',
`pl_title` varbinary(255) NOT NULL DEFAULT '',
UNIQUE KEY `pl_from` (`pl_from`,`pl_namespace`,`pl_title`),
KEY `pl_namespace` (`pl_namespace`,`pl_title`,`pl_from`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `pagelinks`
--
/*!40000 ALTER TABLE `pagelinks` DISABLE KEYS */;
INSERT INTO `pagelinks` VALUES (10,0,'Computer_accessibility'),(12,0,'-ism'),(12,0,'1848_Revolution'),(12,0,'1917_October_Revolution'),
(12,0,'1919_United_States_anarchist_bombings'),(12,0,'19th_century_philosophy'),
(12,0,'6_February_1934_crisis'),(12,0,'A._K._Press'),(12,0,'A._S._Neill'),(12,0,'AK_Press'),(12,0,'A_Greek–English_Lexicon'),(12,0,'A_Language_Older_Than_Words'),
(12,0,'A_Vindication_of_Natural_Society'),(12,0,'A_las_Barricadas'),(12,0,'Abbie_Hoffman'),(12,0,'Absolute_idealism'),(12,0,'Abstentionism'),(12,0,'Action_theory_(philosophy)'),
(12,0,'Adam_Smith'),(12,0,'Adolf_Brand'),(12,0,'Adolf_Hitler'),(12,0,'Adolphe_Thiers'),(12,0,'Aesthetic_emotions'),(12,0,'Aesthetics'),(12,0,'Affinity_group'),(12,0,'Affinity_groups'),
(12,0,'African_philosophy'),(12,0,'Against_Civilization:_Readings_and_Reflections'),(12,0,'Against_His-Story,_Against_Leviathan'),(12,0,'Age_of_Enlightenment'),(12,0,'Agriculturalism'),
(12,0,'Agriculture'),(12,0,'Al-Ghazali'),(12,0,'Alain_Badiou'),(12,0,'Alain_de_Benoist'),(12,0,'Albert_Camus'),(12,0,'Albert_Libertad'),(12,0,'Albert_Meltzer'),(12,0,'Aleister_Crowley'),
(12,0,'Alex_Comfort'),(12,0,'Alexander_Berkman'),(12,0,'Alexandre_Christoyannopoulos'),(12,0,'Alexandre_Skirda'),(12,0,'Alfredo_M._Bonanno')
I am unable to parse the data because it is not very well documented.
The SQL dumps contain directly data from the MySQL table MediaWiki uses. Those tables are documented on mediawiki.org, in your case it's the pagelinks table.
The fields given are p1_from, p1_namespace, and p1_title.
No, that's not a 1 (the number one), it's an l (the letter L), pl is short for pagelinks.
I do not know what p1_from is.
From the documentation, that's “Key to the page_id of the page containing the link.” To find out the name of the page where the links comes from, you will need the page table.
I can't solve my problem with my local Oracle database.
I'm tryong to connect to my local Oracle database (Oracle Database 11g Express Edition)
Later on I will use JNDI to another Oracle Database, but I think this should still work.
Driver: ojdbc6.jar in /lib
db.default.driver=oracle.jdbc.driver.OracleDriver
db.default.url="jdbc:oracle:thin:#localhost:1521:xe"
db.default.user="user"
db.default.pass="pass"
So I know I do connect to the database, but the error is that it says that the table does not exist. I'm not even creating or querying to a table (no model exists - but I've tried with having a model too, same error). Something seems to be wrong in the beginning and I don't know how to Debug this.
Error:
**java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist**
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:400)
oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:926)
oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:200)
oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:543)
oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:197)
oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:1213)
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1492)
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1710)
oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:2006)
oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:1709)
com.jolbox.bonecp.StatementHandle.executeQuery(StatementHandle.java:503)
play.api.db.evolutions.Evolutions$.executeQuery(Evolutions.scala:118)
play.api.db.evolutions.Evolutions$.databaseEvolutions(Evolutions.scala:334)
play.api.db.evolutions.Evolutions$.evolutionScript(Evolutions.scala:306)
play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1$$anonfun$apply$1.apply$mcV$sp(Evolutions.scala:435)
play.api.db.evolutions.EvolutionsPlugin.withLock(Evolutions.scala:478)
play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:434)
play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:432)
scala.collection.immutable.List.foreach(List.scala:309)
play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:432)
play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:63)
play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:63)
scala.collection.immutable.List.foreach(List.scala:309)
play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:63)
play.api.Play$$anonfun$start$1.apply(Play.scala:63)
play.api.Play$$anonfun$start$1.apply(Play.scala:63)
When reading about it I've only found that I might not have permission to some table, but the thing is that I use the same login in Oracle SQL Developer and it works.
As nico_ekito wrote, you need to create this table manually.
This one works for me:
CREATE TABLE play_evolutions
(
id Number(10,0) Not Null Enable,
hash VARCHAR2(255 Byte),
applied_at Timestamp Not Null,
apply_script clob,
revert_script clob,
state Varchar2(255),
last_problem clob,
CONSTRAINT play_evolutions_pk PRIMARY KEY (id)
);
Try to manually create a play_evolutions table with the following columns (by adapting the types to the ones used by Oracle):
id int not null primary key, hash varchar(255) not null,
applied_at timestamp not null,
apply_script text,
revert_script text,
state varchar(255),
last_problem text
In conf/application.conf
Un-comment the following line:
evolutionplugin=disabled
This is if you don't need Evolutions (to track schema changes).