I am trying to drop a column from my DB2 table.
Table name = Instructor
Column name is Page
Command used is:
ALTER TABLE instructor
DROP COLUMN page;
I am getting this error
Column, attribute, or period "PAGE" is not defined in "GFQ70186.INSTRUCTOR".. SQLCODE=-205, SQLSTATE=42703, DRIVER=4.25.1301
Please help me to understand this error
If your column name is Page (i.e. with a capital P and lower case age) then you will need to use double quotes
ALTER TABLE INSTRUCTOR
DROP COLUMN "Page"
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000720.html
Ordinary identifier:
An ordinary identifier is an uppercase letter followed by zero or more characters, each of which is an uppercase letter, a digit, or the underscore character. Note that lowercase letters can be used when specifying an ordinary identifier, but they are converted to uppercase when processed
Delimited identifier:
A delimited identifier is a sequence of one or more characters enclosed by double quotation marks. Leading blanks in the sequence are significant. A delimited identifier can be used when the sequence of characters does not qualify as an ordinary identifier. In this way an identifier can include lowercase letter
Related
Can we use underline with a # sign in column name in SQL?
Like Supplier(Sunp#, SName, Address,City, TelNo) is permissable in SQL or do the underline and # sign have a special meaning?(Assume Sunp to be underlined)
You can, no special meaning.
SQL> create table supplier
2 (sunp# number,
3 supplier_name varchar2(20)
4 );
Table created.
SQL>
Read on Database object names and qualifiers.
Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and "at" signs (#).
Quoted identifiers can contain any characters and punctuations marks as well as spaces. However, neither quoted nor nonquoted identifiers can contain double quotation marks or the null character (\0).
I have a database in Cloudant where the document ID is _id.
After replicating this data from Cloudant to dashDB I have 2 separate tables that I want to join using this _id column. In Run SQL I tried the below, but this would not run. What am I missing here? Do I need to replace the column name _id to something without an underscore?
select m.title, m.year, g.value
from MOVIES m
inner join MOVIES_GENRE g on m._ID = g._ID;
TL;DR: As #gmiley points out the issue is caused by the _ID column name, which is not an ordinary identifier (see definition below) and therefore needs to be enclosed in double quotes "_ID" or single quotes '_ID' in your SQL statements.
select m.title, m.year, g.value
from MOVIES m
inner join MOVIES_GENRE g on m."_ID" = g."_ID";
Unlike ordinary identifiers quoted identifiers are case sensitive ("_id" is not identical to "_ID" whereas title is identical to TITLE). If you were to specify "_id" in your statement an error would be raised indicating that the column wasn't found.
Since you've mentioned that you've used the Cloudant warehousing process to populate your DashDB tables it's probably worth mentioning that property names are upper-cased when the DDL is generated during the schema discovery.
Example: The content of JSON documents with this structure
{
"_id": "000018723bdb4f2b06f830f676cfafd6",
"_rev": "1-91f98642f125315b929be5b5436530e7",
"date_received": "2016-12-04T17:46:47.090Z",
...
}
will be mapped to three columns:
_ID of type VARCHAR(...)
_REV of type VARCHAR(...)
DATE_RECEIVED of type ...
...
Hope this helps!
From the DB2 SQL reference:
An ordinary identifier is an uppercase letter followed by zero or more characters, each of which is an uppercase letter, a digit, or the underscore character. Note that lowercase letters can be used when specifying an ordinary identifier, but they are converted to uppercase when processed. An ordinary identifier should not be a reserved word.
Examples: WKLYSAL WKLY_SAL
A delimited identifier is a sequence of one or more characters enclosed by
double quotation marks. Leading blanks in the sequence are significant.
Trailing blanks in the sequence are not significant, although they are stored
with the identifier. Two consecutive quotation marks are used to represent
one quotation mark within the delimited identifier. In this way an identifier
can include lowercase letters.
Examples:
"WKLY_SAL" "WKLY SAL" "UNION" "wkly_sal"
Will need some advice. In HIVE DB is it possible to create table with column have space as below
CREATE TABLE TEST2("Kod ASS" String)
get an error as below
Error: Error while compiling statement: FAILED: ParseException line 1:19 cannot recognize input near '"Kod ASS"' 'String' ')' in column specification
SQLState: 42000
ErrorCode: 40000
show manual about column names:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
In Hive 0.12 and earlier, only alphanumeric and underscore characters are allowed in table and column names.
In Hive 0.13 and later, column names can contain any Unicode character (see HIVE-6013). Any column name that is specified within
backticks (`) is treated literally. Within a backtick string, use
double backticks (``) to represent a backtick character. Backtick
quotation also enables the use of reserved keywords for table and
column identifiers.
To revert to pre-0.13.0 behavior and restrict column names to alphanumeric and underscore characters, set the configuration property
hive.support.quoted.identifiers to none. In this configuration,
backticked names are interpreted as regular expressions. For details,
see Supporting Quoted Identifiers in Column Names.
CREATE TABLE DB_Name.Table_name (
First name VARCHAR(64), Last name VARCHAR(64), Location id VARCHAR(64) , age INT, gpa DECIMAL(3,2)) CLUSTERED BY (age) INTO 2 BUCKETS STORED AS ORC;
OR
CREATE TABLE TEST2(Kod ASS String) STORED AS TEXTFILE;
You can use and put column name inside.
I hope both worked for you.
When I create the table, I got this error ORA-00904: : invalid identifier, I don't know what the error means.
Create table c_stock(s_date date not null,
o_stock number(4),
add number(4),
total number(4));
From the ORA-00904 description:
ORA-00904 string: invalid identifier
Cause: The column name entered is either missing or invalid.
Action: Enter a valid column name. A valid column name must begin with
a letter,be less than or equal to 30 characters, and consist of only
alphanumeric characters and the special characters $, _, and #. If it
contains other characters, then it must be enclosed in double
quotation marks. It may not be a reserved word.
Looking at the list of Oracle reserved words, ADD appears on the second row.
Changing that column name should resolve your problem.
I have a database, which holds many first names, occurring like the following pattern:
The name can consist of many first names (like double, or triple names), separated by either a '-' or a ' '.
Each of the names consists of either lowercase or UPPERCASE letters or a capital first letter and the rest lowercase.
I would like to write a query to count all names which have either just UPPERCASE letters, or do not have a capital letter after a break of two words.
Sample Table and Data
CREATE TABLE names( name VARCHAR, PRIMARY KEY(name) );
INSERT INTO names values('Veronika isabella');
INSERT INTO names values('Veronika Isabella');
INSERT INTO names values('Michael Karl Otto- Emil');
INSERT INTO names values('Michael karl-Otto-emil');
INSERT INTO names values('philipp');
INSERT INTO names values('Philipp');
SELECT count(*) AS misfits
FROM names
WHERE name !~ '[[:lower:]]' -- not a single lower case letter
OR name ~ '\m[[:lower:]]' -- lower case letter at beginning of a word
OR name ~ '[[:lower:]][[:upper:]]'; -- lower case letter after upper case
Details in the manual.
Or maybe initcap() fits your requirements (like a_horse commented).
SELECT count(*) AS misfits
FROM names
WHERE name <> initcap(name);
SQL Fiddle.