Can I use question marks in SQLite table column name? - sql

When I try to create a table with the following as a column name: "Admin?" in my SQLite Database, I get a SQL error saying:
SQL error or missing database (near "?": syntax error)
Here is my SQL statement:
CREATE TABLE test (admin? TEXT PRIMARY KEY);
I am assuming I cannot have question marks inside column names, but I cannot find any documentation about it. If this is the issue, is there any workaround here, or a better solution? Also, I am creating the table from Kotlin code, so I am not sure if that has any effect on it.

Escape the column name:
CREATE TABLE test ("admin?" TEXT PRIMARY KEY);

Related

Dropping XML columns in DB2

I'm trying to drop an XML column in db2 in the following manner. But every time I do this, it is resulting in an error
create table One(name int, address XML);
alter table One add column age xml;
alter table One drop column age;
Error starting at line : 5 in command -
alter table One drop column age
Error report -
DB2 SQL Error: SQLCODE=-1242, SQLSTATE=42997, SQLERRMC=7, DRIVER=4.11.77
DB2 official documentation suggests that issue is fixed in DB 9.7. I'm currently checking on 10.5 & 11.5 versions but still facing the same issue.
https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/xml/src
/tpc/db2z_alterxml.html
DB2 documentation suggests to run CHECK pending status on a table after a re-org but there were no commands that are available.
Is there a way to resolve this drop column issue for XML datatypes? Or else DB2 is not allowed to drop XML columns in a table by default?
Can someone suggest on this issue?
https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.wn.doc/doc/c0055038.html
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.messages.sql.doc/com.ibm.db2.luw.messages.sql.doc-gentopic5.html#sql1242n
IBM suggests all the XML columns in a table need to dropped in a single alter statement. Is this still a restriction in 10.5 & higher versions of db2 ?
This remains a restriction in Db2-Linux/Unix/Windows up to and including Db2 v11.5.
IBM states (in the help for SQL1242N reason code 7)
"For a table containing multiple columns of data type XML, either do
not drop any XML columns or drop all of the XML columns in the table
using a single ALTER TABLE statement
"
This restriction only applies to tables with more than one XML column.
You can workaround in various ways, for example create a new table and copy the existing data into it etc, or arrange your physical data model differently.

Hive allowed column names

I am completely new to Hive. While creating a Hive table, I came across following error:
>create table coffee (WINDOW int);
Error: Error while compiling statement: FAILED: ParseException line 1:23
cannot recognize input near 'WINDOW' 'int' ')' in column specification
(state=42000,code=40000)
When I digged more, I realized its happening due to reserve keyword "Window" which I have used while creating table in Hive. Can I get a list of all reserve keyword in Hive which can not be used as a column name. I got a list of reserve keywords at following link, but I am able to use lot of listed reserve keywords as column name from it while creating table.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
you can use backtick quotes to create tables/column with keyword names like this
create table coffee (`WINDOW` int);
Anyway, I would recommend choose a different name, if you want to select the data by column name, you will also must use the backtick quotes
You can't use reserved keywords as column name.
WINDOW is a reversed keyword. So use some other name for your variable.
Edit: use backtick quotation (``) like below:
create table coffee ( `WINDOW` int);

Trying to create a new column, get #1064 error

I've been using phpMyAdmin to manage my db without any problem, but today I ran into this error if I try to add any column by using the interface to any table of any database:
ALTER TABLE `testing` ADD `faaa` INT NOT NULL AFTER ;
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
But if I add the column via SQL command in phpMyAdmin, this time by removing AFTER, the column is added without any problem.
I'm still inexperience with phpMyAdmin, so I guess I must have missed a mandatory field to fill when creating a new column in the interface. Can anyone shed a light on this for me?
AFTER column_name is used to designate which column in the table you want to insert the new column after. You're providing the AFTER without telling it which column you want the new column to be inserted behind. If you don't care about the order of the columns in your table, omit the AFTER, and the new column will be inserted at the end of the column list.
You have no column name after the AFTER statement, so the phpMyAdmin doesn't know where it should be put. Whether it's you forgetting to select the column or a phpMyAdmin bug, I have no idea because for adding a new column, the only required fields are the name and type, which you have.

postgres database column name not recognized

I'm using postgresql database, in a table, I have a column named date.
The problem occurs when I try making some operations with this column (date).
For example:
create index tg_index ON table_replay using btree(date);
here is my error:
ERROR: column "date" does not exist
****** Error ******
ERROR: column "date" does not exist SQL state: 42703
PS: I cannot change this column name because this is a big database so i need many years to perform any change. Thanks for understanding.
Change your column name from date to another such as date because date is a reserved word. You can easily achieve this by using alter commmand. Using alter command dosen't take too much time because alter command only affects the table structure reather than the data of the table. alter command have no concern with the data of the table.
http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html says date is a reserved keyword. You can try quoting it. That may not work.
I agree witht he above comment - use of plain keywords that have a generic sense is generally a bad practice - column names should help to describe the purpose of the column.

Simple question on a SQL create table

I was actually in process of creating a sample table in my test database when somehow I missed out on proper syntax and came up with this statement for create table -
CREATE TABLE A (id as INT, column1 as nvarchar(10))
and when I tried to execute this statement, I got the error below -
'nvarchar' is not a recognized built-in function name.
Altough, I found that I should not have used "as" in the column declaration and corrected it, I am now curious on why I got this error for only nvarchar and not for INT.
Also why this error instead of a incorrect syntax or something like that.
Thanks in advance.
AS is used to define computed columns. Therefore SQL Server expects an expression here, and this "looks" like a function call.
Computed columns info on MSDN for SQl Server 2005