How to drop a column starting with a Digit in Netezza - sql

Due to some error while uploading data, extra columns got created and one of the column names became 84. Trying to remove that column but getting following error:
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [1100] [HY000]: ERROR: 'ALTER TABLE XXX.XXXXX
DROP 84'
error ^ found "84" (at char 44) expecting an identifier, identifiers must begin with a letter

You can find examples of how to handle identifiers that does does not begin with a letter. You can wrap the identifier in double quotes
https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.1/com.ibm.nz.dbu.doc/c_dbuser_handle_sql_identifiers.html

Related

ERROR: invalid input syntax for type numeric: ""

ALTER TABLE unicorns
ALTER COLUMN last_valuation_upd TYPE numeric USING (last_valuation_upd::numeric);
It shows this error:
ERROR: invalid input syntax for type numeric: "" SQL state: 22P02
I am assuming you had the column as text before and now changing it to numeric. Probably the quotes and commas (if any) existing in the table can be a problem and may need to be removed.

Alter column length in SQL

ALTER TABLE tableName
MODIFY COLUMN columnName VARCHAR (256);
Error :
Incorrect syntax near 'VARCHAR'
The syntax for modifying a column definition is depending on used database. For Microsoft SQL Server for example, you would need to replace MODIFY COLUMN with ALTER COLUMN.
For better help you should specify your database type.

sql Error in derby - ERROR 42X01: Syntax error: Encountered "KEY"

following query gives error like ERROR 42X01: Syntax error: Encountered "KEY" at line 1, column 48.
I am not able to understand what is the exact issue. column KEY is exist and datatype is integer.
Insert into UOM_TYPE
(UNITS_OF_MEASURE_NO,TYPE,KEY,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,VERSION)
values
(79,'Clinical Property',32,'JRL',DATE('2007-05-04'),'JRL',DATE('2007-05-04'),2);
Please help me to resolve the issue
KEY is a Keyword in derby db. you have to escape it :
Insert into UOM_TYPE
(UNITS_OF_MEASURE_NO,TYPE,"KEY",CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,VERSION)
values
(79,'Clinical Property',32,'JRL',DATE('2007-05-04'),'JRL',DATE('2007-05-04'),2);

is "following" a reserved keyword in Hive?

Hive command - create table table_name (accountId string,name string,following string);
throws following exception,
[main] ERROR org.apache.hadoop.hive.ql.Driver - FAILED: ParseException line 2:198 cannot recognize input near 'following' 'string' ',' in column specification
org.apache.hadoop.hive.ql.parse.ParseException: line 2:198 cannot recognize input near 'following' 'string' ',' in column specification
In the below link,"following" is not mentioned in the reserved keywords list,
http://docs.treasuredata.com/articles/faq
I think it might be in the reserved key word list. However you can use the below query to create the column name following.
create table test (accountId string,name string,`following` string);

Following regex is not working

I have this constraint in the SQL Server statement.
([VehNo] like '[a-zA-Z][a-zA-Z],[a-zA-Z][0-9][0-9][0-9][0-9][a-zA-Z]')
But when I try to insert data this is giving me error.
INSERT INTO [dbo].Car
VALUES ('SGD1234F','Ferrari','F30','2014-09-24','500000.00','500.00','excellent');
The error is as follows
Msg 547, Level 16, State 0, Line 2 The INSERT statement conflicted
with the CHECK constraint "vehNo_ck_validity". The conflict occurred
in database "t322", table "dbo.Car", column 'VehNo'. The
statement has been terminated.
What is the change that I have to make?
Your regexp contains an unwanted comma. I have added spaces to highlight comma in your regexp.
[a-zA-Z][a-zA-Z] , [a-zA-Z][0-9][0-9][0-9][0-9][a-zA-Z]
For such regexp, VehNo should be SG,D1234F
Remove extra comma and your insert statement will work.
This is another version of your regexp: [a-zA-Z]{3}\d{4}[a-zA-Z]