Sqlalchemy Teradata ODBC 17.00 to_sql QVCI error CAST CLOB type to DATE - pandas

I am trying to use pandas to_sql to an existing table in Teradata database but I got this QVCI error. After some research online, I upgraded my ODBC driver to 17.00 but I still get the same error.
Existing Table:
I am using sqlalchemy_teradata
Here is the code:
a_df.to_sql(name='TEST_LA_TEMP', con=engine, schema='DB', if_exists='replace', index=False)
I then tried to specify the types but got the same error.
from sqlalchemy.types import INTEGER, VARCHAR, Date
a_df.head()
a_df.to_sql(name='TEST_LA_TEMP', con=engine_ldap, schema='DB', if_exists='replace', index=False
, dtype={'id': INTEGER,
'p_name': VARCHAR(20),
'dept': VARCHAR(20),
'update_date': Date})
ERROR:
DatabaseError: (teradata.api.DatabaseError) (9719, '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database](-9719)QVCI feature is disabled.')
[SQL: SELECT *
FROM dbc.ColumnsQV
WHERE DatabaseName (NOT CASESPECIFIC) = CAST(? as VARCHAR(128)) (NOT CASESPECIFIC) AND TableName=?]
[parameters: ('DB', 'TEST_LA_TEMP')]
When I use the same code to import to an NEW (non-existing) table, it works fine but returns CLOB as datatype for most columns
I then tried to CAST CLOB Types to the correct Types but it said CLOBs can only be converted to CHAR TO VARCHAR missing my update_date column.
I can get it working if I use if_exists='append' instead, and then drop and create table again. but I still want to understand why and how to resolve these errors.
Questions:
What is the syntax to enable QVCI directly for Teradata?
Is there a way to CAST CLOB to DATE? How?
Why if_exists='replace' depends on QVCI but not if_exists='append'?
Thank you!

Related

SQL - Error converting data type nvarchar to float

I am trying to convert data type of one of my columns (the table was imported from Excel), and then it shows an error
Error converting data type nvarchar to float
Code:
ALTER TABLE [dbo].[games_activity_2020$]
ALTER COLUMN [Version] float
What can I do differently?
probably there might be any character values inserted in the table while importing from excel. You can check those values using the below query
SELECT version
from [dbo].[games_activity_2020$]
where TRY_CONVERT(float, version) IS NULL
you can update those values and try to ALTER the table again
I suggest you run
SELECT * FROM [dbo].[games_activity_2020$]
WHERE TRY_CAST([Version] as FLOAT) IS NULL
and fix up any problematic values

Failed to execute query. Error: String or binary data would be truncated in table xdbo.user_info', column 'uid'

I have problem inserting values in my SQL server database on Azure, I am getting the following error:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
I don't understand where I am wrong, I just created the server, and I am trying to experiment but cant fix this.
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
Creating the table works fine, the only thing that doesn't work is the second command INSERT
I suspect that the reason is that you haven't defined a lenght for varchar and it defaults to 1 as length. Therefore your value gets truncated.
Set a varchar length to something like varchar(200) and you should be good to go.
This looks like the fact that the CREATE portion of your procedure for the table doesn't include a length of varchar, so you'd have to specify a length such as varchar(50) since the default is 1. Refer to the official MS docs in the link, in the remarks.
docs.miscrosoft.com
Also, here is the syntax for the CREATE TABLE in Azure which might be helpful as well.
Syntax of Azure CREATE TABLE

OUTPUT TO FILE LOCAL SYBASE IQ 16

I'm trying to write my existing tables to files and save it locally.
I'm using T-SQL with SQuirrel JDBC Connection to Sybase
I tried the following Code to write results into a file:
SELECT * FROM date_dimension;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;
I dont know why it doesn't work but I get a Syntax error while trying this.
Error: SQL Anywhere Error -131: Syntax error near 'OUTPUT' on line 1
SQLState: 42W04
ErrorCode: 102
Can someone see a mistake in the code? Is there another way to write into file from Sybase IQ?
I'm new to all this Tools and I'm sry for such a question
Please help me :)
CREATE TABLE DATE_DIMENSION
( [DateKey] INT primary key,
[Date] DATETIME,
[FullDateUK] CHAR(10), -- Date in dd-MM-yyyy format
[FullDateUSA] CHAR(10),-- Date in MM-dd-yyyy format
}
That should work, your syntax is correct, can you provide the ddl of the table?
Edit: try this select statement:
select DateKey,("Date"),FullDateUK,FullDateUSA from DATE_DIMENSION;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;

Bulk inserting data gives error

Attempting to bulk insert into a table and I am getting the error:
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 31, column 4 (Birthday).
Below is the code I am trying to use to insert the data:
Bulk Insert Dzt.dbo.Player
From 'A:\New Folder\Seed_Files\Player.csv'
With
(
FieldTerminator=',',
RowTerminator='\n',
FirstRow=2
)
Here is the code I used when making the table:
Use Dzt
Create Table Player
(
Player_ID int,
FirstName varchar(255),
LastName varchar(255),
Birthday date,
Email varchar(255),
L_Flag varchar(255)
);
This is my first attempt at making a table and inserting data so I am thinking it is likely a datatype error for the Birthday field but I have been unable to find anything online that I am able to grasp my head on at this time. I have also tried use the datatype datetime instead of date but I received the same error.
I am using SSMS 2012 to create and insert the data onto a 2012 SQL Server.
Let me know if there is anything else I can provide that might help.
As you suspect it could be a date format error, I would suggest importing the csv into a table with Birthday column set to varchar type. Then use this query to filter the erroneous records.
select birthday from temptable where isdate(birthday) = 0
You could then correct those records and then insert them into your old table.

error converting data types when importing excel file into sql server

As a SQL beginner, I am trying to import data from Excel to a table in sql server. I imported the data using sql import wizard. Since the wizard always defaut some of my numeric columns into nvarchar and won't allow me to change it in mapping, I planned to import the data into a temp table, then use INSERT with CAST function to transfer the data into the permanent target table.
When doing the insert, however, I got the error of 'error converting data type nvarchar to numeric'. anyone can tell me why and how to solve the issue? Here is my code:
INSERT INTO [DatabaseA].[dbo].[mstr_Project]
([Project_Start_Year]
,[Project_Name]
,[Client_Name]
,[Client_Revenue_in_Millions]
,[Client_Employee_Number])
SELECT [ProjectStartYear]
,[ProjectName]
,[ClientName]
,CAST([ClientRevenuesInMillions] AS NUMERIC)
,CAST([EmployeeNo] AS NUMERIC)
FROM [dbo].[temp_ProjectImport]
Thanks a million!!
you could do this convert(nvarchar(255), #col)
INSERT INTO [DatabaseA].[dbo].[mstr_Project]
([Project_Start_Year]
,[Project_Name]
,[Client_Name]
,[Client_Revenue_in_Millions]
,[Client_Employee_Number])
SELECT [ProjectStartYear]
,[ProjectName]
,[ClientName]
,CAST([ClientRevenuesInMillions] AS NUMERIC)
,CONVERT(NVARCHAR(255),[EmployeeNo] ) as new_converted_value
FROM [dbo].[temp_ProjectImport]