Closed Pietro395 closed 2 months ago
Is the "other client" also using FreeTDS?
Is the "other client" also using FreeTDS?
No, i'm using Dbeaver with a JDBC Driver
Can you please then check if this is also happening with FreeTDS and pyodbc
? I would currently guess that this is a FreeTDS issue as ODBC errors
are normally completely inside the ODBC driver, not turbodbc
.
MS SQL Server does not allow the alias to be used in the WHERE clause. (I believe Oracle does allow this.) Try writing the WHERE clause in longhand, as follows:
SELECT dbo.View_Log.ID, dbo.View_Log.Postazione,
dbo.View_Log.Data, dbo.View_Log.ora, CAST(Data as DATETIME) + CAST(ora as DATETIME) AS pippo
FROM dbo.View_Log
WHERE CAST(Data as DATETIME) + CAST(ora as DATETIME) >= ?
AND CAST(Data as DATETIME) + CAST(ora as DATETIME) < ?;
Can you please then check if this is also happening with FreeTDS and
pyodbc
? I would currently guess that this is a FreeTDS issue asODBC errors
are normally completely inside the ODBC driver, notturbodbc
.
Same problem!
'42S22', "[42S22] [FreeTDS][SQL Server]Invalid column name 'pippo'. (207) (SQLExecDirectW)")
Alternatively, use a subquery or CTE:
WITH T AS
(
SELECT ID, Postazione, Data, ora, CAST(Data as DATETIME) + CAST(ora as DATETIME) AS pippo
FROM dbo.View_Log
)
SELECT * FROM T
WHERE pippo >= ?
AND pippo < ?;
MS SQL Server does not allow the alias to be used in the WHERE clause. (I believe Oracle does allow this.) Try writing the WHERE clause in longhand, as follows:
SELECT dbo.View_Log.ID, dbo.View_Log.Postazione, dbo.View_Log.Data, dbo.View_Log.ora, CAST(Data as DATETIME) + CAST(ora as DATETIME) AS pippo FROM dbo.View_Log WHERE CAST(Data as DATETIME) + CAST(ora as DATETIME) >= ? AND CAST(Data as DATETIME) + CAST(ora as DATETIME) < ?;
Thank you, but this way i have this error:
Unsupported type identifier for column ora @ UNKNOWN TYPE (precision 16, scale 7))
SELECT dbo.View_Log.ID, dbo.View_Log.Postazione,
dbo.View_Log.Data, dbo.View_Log.ora, CAST(Data as DATETIME) + CAST(ora as DATETIME) AS pippo
FROM dbo.View_Log
WHERE CAST(dbo.View_Log.Data as DATETIME) + CAST(dbo.View_Log.ora as DATETIME) >= ?
AND CAST(dbo.View_Log.Data as DATETIME) + CAST(dbo.View_Log.ora as DATETIME) <= ?;
Alternatively, use a subquery or CTE:
WITH T AS ( SELECT ID, Postazione, Data, ora, CAST(Data as DATETIME) + CAST(ora as DATETIME) AS pippo FROM dbo.View_Log ) SELECT * FROM T WHERE pippo >= ? AND pippo < ?;
mmh.. also the same error:
Error! Unsupported type identifier for column ora @ UNKNOWN TYPE (precision 16, scale 7))
WITH T AS
(
SELECT dbo.View_Log.ID, dbo.View_Log.Postazione,
dbo.View_Log.Data, dbo.View_Log.ora, CAST(dbo.View_Log.Data as DATETIME) + CAST(dbo.View_Log.ora as DATETIME) AS pippo
FROM dbo.View_Log
)
SELECT * FROM T
WHERE T.pippo >= ?
Column ora is TIME datatype in DB https://imgur.com/7GH6jRU
@xhochy Does turbodbc support TIME datatypes? Issue #85 implies is doesn't, but the docs state it does.
@xhochy Does turbodbc support TIME datatypes? Issue #85 implies is doesn't, but the docs state it does.
I was relying on the documentation and I was assuming it was supported
@xhochy Does turbodbc support TIME datatypes? Issue #85 implies is doesn't, but the docs state it does.
Someone would need to write a test, I'm not using any TIME type, so it could be that this isn't working.
@xhochy Does turbodbc support TIME datatypes? Issue #85 implies is doesn't, but the docs state it does.
Someone would need to write a test, I'm not using any TIME type, so it could be that this isn't working.
Is it normal that I don't see the TIME data type here? https://github.com/blue-yonder/turbodbc/blob/master/python/turbodbc/data_types.py
Hello, there are any news for this problem?
At this point @pietromingo , I'm assuming turbodbc does not support TIME datatypes. Hence, you won't be able to retrieve the "ora" column directly. Having said that, in the scenario you describe, I don't think you need to retrieve it separately at all. You are retrieving it indirectly in the "pippo" column, and you can retrieve the time portion of "pippo" in your Python code. If you really need to retrieve "pippo" separately though, you can always convert it to a DATETIME first. Not ideal I know, but it should get you going.
At this point @pietromingo , I'm assuming turbodbc does not support TIME datatypes. Hence, you won't be able to retrieve the "ora" column directly. Having said that, in the scenario you describe, I don't think you need to retrieve it separately at all. You are retrieving it indirectly in the "pippo" column, and you can retrieve the time portion of "pippo" in your Python code. If you really need to retrieve "pippo" separately though, you can always convert it to a DATETIME first. Not ideal I know, but it should get you going.
Thanks, you're right, I was focusing on the query and I hadn't thought about this detail!
I am using turbodbc on a Linux environment using FreeTDS as a Driver.
I find myself with a table with a DATE and a TIME column, combining these two columns into a new one of the DATETIME type and giving it an alias, when I use this column in a WHERE always getting the following error:
This is my query:
The query works correctly using another client
Can someone help me?