Setting default value as custom sequence - go

Question regarding the declaration of primary key with default value.
Using cockroachDB, we can create sequence to basically have ID starting from 1, with regular increment of 1.
create sequence for cockroachdb
Trying to create my model with default value nextval('sequence_name')
`gorm:"DEFAULT:nextval('sequence_name')"`
Tried this one above, but it's not working (edited)

Related

auto increment of data(int type) which is not Id(identity already used) ASP.NET MVC

I am trying to auto increment data, which is not Id, I have used Sql Identity on Id so can't use it anymore. I tried sql sequence to bind data column and it works if I add information from sql via script but it does not work on adding from visual studio. I tried to [DatabaseGenerated(DatabaseGeneratedOption.Computed)] but it does not work too. I have been searching this topic for 2 days in web but can't find any solution
You can use SQL Sequences for this. According to the documentation by Microsoft
A sequence is a user-defined schema bound object that generates a sequence of numeric values according to the specification with which the sequence was created. The sequence of numeric values is generated in an ascending or descending order at a defined interval and can be configured to restart (cycle) when exhausted. Sequences, unlike identity columns, are not associated with specific tables. Applications refer to a sequence object to retrieve its next value. The relationship between sequences and tables is controlled by the application. User applications can reference a sequence object and coordinate the values across multiple rows and tables.
You can create a sequence using the syntax below:
CREATE SEQUENCE OrderNumber
START WITH 1
INCREMENT BY 1 ;
GO
To check how it can be used in MVC, please check this post.
Hope this helps!

postgresql custom primarykey

I try to make a project using hibernate and postgres as DB. The problem I have is I need to store the primary key as this 22/2017 or like 432/1990.
Let's say the first number is object_id and second year_added.
I think what I want to achieve is to make a first number and second number together a primary key so 22/2017 is different from 22/2016.
The only idea I have is when user add new object I generate current date year and trying to find last id and increment it.
So next year first added object should be : 1/2018.
So far in my db only object_id is stored as a primary key.
This solution seems to work fine:
PostgreSQL: Auto-increment based on multi-column unique constraint
Thanks for helping me anyway.

Using variables in From part of a task flow source

Is there any way to use a variable in the from part (for example SELECT myColumn1 FROM ?) in a task flow - source without having to give the variable a valid default value first?
To be more exact in my situation it is so that I'm getting the tablenames out of a table and then use a control workflow to foreach over the list of tablenames and then call a workflow from within that then gets data from these tables each. In this workflow I have the before mentioned SELECT statement.
To get it to work properly I had to set the variable to a valid default value (on package level) as else I could not create the workflow itself (as the datasource couldn't be created as the select was invalid without the default value).
So my question here is: Is there any workaround possible in this case where I don't need a valid default value for the variable?
The datatables:
The different tables which are selected in the dataflow have the exact same tables in terms of columns (thus which columns, naming of columns and datatypes of columns). Only the data inside of them is different (thus its data for customer A, customer B,....).
You're in luck as this is a trivial thing to implement with SSIS.
The base problem for most people is that they come at SSIS like it's still DTS where you could do whatever you want inside a data flow. They threw out the extreme flexibility with DTS in favor of raw processing performance.
You cannot parameterize the table in a SQL statement. It's simply not allowed.
Instead, the approach that people take is to use Expressions. In your case, assuming you had two Variables of type String created, #[User::QualifiedTableName] and #[User::QuerySource]
Assume that [dbo].[spt_values] is assigned to QualifiedTableName. As you loop through the table names, you will assign the value into this variable.
The "trick" is to apply an expression to the #[User::QuerySource]. Make the expression
"SELECT T.* FROM " + #[User::QualifiedTableName] + " AS T;"
This allows you to change out your table name whenever the value of the other variable changes.
In your data flow, you will change your OLE DB Source to be driven by a query contained in a variable instead of the traditional table selection.
If you want an example of where I use QuerySource to drive a data flow, there's an example on mixing an integer and string in an ssis derived column
Create a second variable. Set its Expression to create the full
Select statement, using the value of the first variable.
In the Data Source, use "SQL command from variable" option for the
Data Access Mode property.
If you can, set a default value for the variable you created in step
That will make filling out the columns from your data source much easier.
If you can't use a default value for the variable, set the Data
Source's ValidateExternalMetadata property to False.
You may have to open the data source with the Advanced Editor and
create Output columns manually.

making a global variable and incrementing in function - CodeIgniter

I'm trying to make a global variable in my model to increment an id field in my mysql table, but CI won't allow me to make global variables.
I've searched around and people are mentioning having to create a library and declaring the global variable there, and then loading the library in the model and using the variable.
I understand that approach, but how/where would I be able to increment the variables value so that the next time it's called in a function it will be +1?
Thank you in advance for any help
edit: the thing I'm trying to do is whenever I insert a new row in a table, I want to continue on from the last entries id number i.e. last id number in the table is 9, I want to increment on from that number and make the new rows id number 10
If you're able to access the database through CI you can use the Active Record count_all() function.
From CI docs http://ellislab.com/codeigniter/user-guide/database/active_record.html
Permits you to determine the number of rows in a particular table.
Submit the table name in the first parameter. Example:
echo $this->db->count_all('my_table');
// Produces an integer, like 25
You would just get the number of rows in the table returned and add 1 for the row in your new entry.

Oracle: error while trying to use formulas

I created an element with an input value of type "Day" , when i write a formula i get this error.
Any idea what's wrong?
APP-FF-33232:
EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE has null or not found allowed, but no
default set specified.
Cause: If a Database Item has
null allowed, or not found allowed,
then the item must also specify a
default set to be used to provide
default values in the event of these
occurring. The item named has one of
these conditions allowed, but the
default set column in the
FF_DATABASE_ITEMS table is null.
Action: Please refer to your
local support representative.
-
I'm not an expert in Oracle Apps (to say the least) but the error message is fairly clear. You - or someone - have written a Fast Formula which references a database column EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE. Apparently this column can be nullable, in which case your Formula needs to provide a default value. Something like:
default for EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE is 01-JAN-2010
Or perhaps you can use SYSDATE or CURRENT_DATE rather than a fixed value.
Solution to error: You called database item in Fast formula,
you need to initialize the date to specific date
alias EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE as day
default for day is 01-jan-2010

Resources