With libfq and the C API, is there a way to get the nullable metadata of a column from a query?
I'm just talking about the property of a column, not the NULL value from a resultset.
For instance, with MySQL:
mysql_fetch_field_direct()
does the job.
I tried with PQfmod, but without success.
Information about the table definition is not part of the result set data.
You can find out if the value is NULL, but not if the column is nullable or not.
A column in a result set need not be related to a certain column in a table!
To get information about a column's definition, query information_schema.columns. The is_nullable column will contain the information.
Related
I have a table with over 70 million rows which I want to partition using the date/time column, however the date/time column has varchar datatype instead of date.
What is the best way of converting the datatype dynamically to be able to use the column as a partition range ?
Thanks
I suggest you add a new PERSISTED COMPUTED column and then create partition on the computed field.
The computed column should be type of date and it is simply conversion of your varchar column.
I have done this before as experiment and it works.
I use SSIS in SQL Server 2016. I have to create a new column in my DataFlow. I use DrivedColumn component to create this new column. In this case I need a nullable numeric column like below image :
As you can see, I have error in this case.
How can I create null-able numeric in Derived column component?
In the derived column task there are NULL Functions that you can use if you would like to set a value to NULL.
Select the appropriate NULL function that corresponds to the datatype of your column and plug that into your equation.
You can use NULL(DT_CY) if your column is defined as currency.
Example. ([currencyAmount]>0? [currencyAmount]:NULL(DT_CY)
In the Derived Column task Null Functions can be found here:
In SQL Server, how can we switch off the PERSISTED attribute of a computed column using T-SQL? I am able to do this using Management Studio GUI but do not know how to do it using T-SQL.
If you want to drop the PERSISTED property from your column, then you can try the following:
ALTER TABLE dbo.MyTable ALTER COLUMN MyColumn DROP PERSISTED;
According to MSDN:
[ {ADD | DROP} PERSISTED ]
Specifies that the PERSISTED property is added to or dropped
from the specified column. The column must be a computed column that is
defined with a deterministic expression.
Related: You can also have a look at this article by Aaron Bertrand.
You can do this by following this steps:
Create a new column in your table having the same datatype as that of your persisted column.
Update the new column with the persisted column value.
Remove the persisted column from your table.
Rename the new column as that of the persisted column.
I am trying to use a TAdoquery with MS SQL Server in a legacy delphi project.
The dataset contains a field that represents identity column in the SQL table. It has AutogenerateValue = arAutoInc and ProviderFlags [pfInWhere, pfInKey]. It also has Required = false.
After doing adoquery.Append I prefill fields and try to do adoquery.Post but get this error:
Non-nullable column cannot be updated to Null
All non-nullable fields are set to non-null before post, so the identity column is the only suspect. The TADOQuery has no joins (simple Select * from my_table), but it has look up fields and calculated fields, which may be null. For lookup fields and calculated fields I removed provider Flags to ensure those fields do not appear in the insert or update statement.
The identity field is NULL immediately before post, I see no insert command firing on the server in the Profiler, instead I just get this error.
Is it possible to preview the sql statement generated by the Tadoquery to insert a new row ?
I solved it, the issue was of course unrelated to the identity column.
The initial sql was select * from myTable, which meant that it also loaded a couple of extra columns that were not bound to any grid column in my DBGridEh.
After replacing * with an explicit list of the columns that I needed the INSERT worked.
Hopefully the title has made it quite clear.
I would like to see an example of a alter table statement that can change an existing non-nullable column in a Sybase table to nullable.
Modifying the NULL default value of a column:
If you are changing only the NULL default value of a column, you do not need to specify a column's datatype
(Switching the example from the above link):
alter table authors
modify address null