How to declare a model start with '_' in Gorm? - go-gorm

I'm trying to declare a model and insert some data in a table with a column named '_update_time'.
type User struct{
...
UpdateTime time.Time `gorm:"column(_update_time)"`
...
}
However, it doesn't work with the Error 'Unknown column 'update_time' in 'field list'.
It works when I try to "create from map" but I need the back filled primary key :(

Related

SAP DBTech JDBC: [1306]: return type mismatch:Procedure ARRAY_UNNEST_SIMPLE: Attribute name "id" different from Attribute name: ":ARRID"

Hello everyone I am learning about SAP HANA. I'm having trouble at this error, I've been trying to figure out how to fix it but I haven't figured it out yet, I hope everyone will help. Thank you all.
DROP TYPE ttype;
CREATE TYPE ttype AS TABLE("ID" INT , "NAME" NVARCHAR(10));
CREATE PROCEDURE ARRAY_UNNEST_SIMPLE(OUT rst ttype)
AS
BEGIN
DECLARE arrid INTEGER ARRAY = ARRAY (1,2);
DECLARE arrname NVARCHAR(10) ARRAY = ARRAY('name1', 'name2', 'name3');
rst = UNNEST(:arrid, :arrname);
END;
It looks like the error is due to the mismatch of the column names that result from the UNNEST operation and the declared return table variable.
You can provide column names via the AS ... command parameter:
rst = UNNEST(:arrid, :arrname) AS (“ID”, “NAME”)

ERROR: invalid input syntax for type numeric (SQL)

I've created a data set with Mockaroo and then added the file with cmd. But I am getting this error.
ERROR: invalid input syntax for type numeric:
The table definiton is this :
create table car(
id BIGSERIAL NOT NULL PRIMARY KEY,
make VARCHAR(100) NOT NULL,
model VARCHAR(100) NOT NULL,
price NUMERIC(19,2) NOT NULL);
And this is how the numeric number (price) looks like:
insert into car (id, make, model, price) values (1, 'Mercury', 'Grand Marquis', '$52656.16');
I added the cmd screen shot for you to see.
Note : the translated version of the error written in my cmd is:
ERROR: invalid input syntax for type numeric:
p.s : I tried making (19,2) to even (50,20). It did not work.
cmd
Your price column is numeric and data that you are entering into it is varchar('$52656.16')
Either replace '$52656.16' with numeric value 52656.16 or change price column to varchar.
If you use VARCHAR for the price column you may still get a invalid input syntax for type numeric error.
What i think you should try is changing the data sets from mockaroo by changing the money option with numbers and add the decimals (you can choose 2 decimals option) option. You should have a data set without the $ sign.

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

HSQLDB (HyperSQL): Changing column type in a TEXT table

For the CsvCruncher project,
I am loading a CSV file into HSQLDB.
CREATE TEXT TABLE concat_1 ( Op VARCHAR(255), id VARCHAR(255), uuid VARCHAR(255), session_id VARCHAR(255) )
SET TABLE concat_1 SOURCE '.../concat_1.csv;encoding=UTF-8;cache_rows=50000;cache_size=10240000;ignore_first=true;fs=,;qc=\quote'
At the time of creating the table and loading, I don't know anything about the column values.
To speed the SELECTs up, I am trying to convert the columns (after loading) to other types, relying on this HSQLDB feature:
"HyperSQL allows changing the type if all the existing values can be cast
into the new type without string truncation or loss of significant digits."
ALTER TABLE concat_1 ALTER COLUMN id SET DATA TYPE BIGINT
But when I try that, I get:
operation is not allowed on text table with data in statement
Is this possible with HSQLDB without duplicating the TEXT table into a normal (native) table?
Here's the code, for your imagination:
for (String colName : colNames) {
String sqlTypeUsed = null;
for (String sqlType : new String[]{"TIMESTAMP","UUID","BIGINT","INTEGER","SMALLINT","BOOLEAN"}) {
String sqlCol = String.format("ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE %s",
tableName, colName, sqlTypeUsed = sqlType);
log.info("Column change attempt SQL: " + sqlCol);
try (Statement st = this.conn.createStatement()) {
st.execute(sqlCol);
log.info(String.format("Column %s.%s converted to to %s", tableName, colName, sqlTypeUsed));
} catch (SQLException ex) {
log.info(String.format("Column %s.%s values don't fit to %s.\n %s",
tableName, colName, sqlTypeUsed, ex.getMessage()));
}
}
}
I figured out. Although it's not documented, TEXT tables can't be altered while bound to a CSV file.
What I did:
1) Instead of trying ALTER with each type, I queried SELECT CAST (<col> AS <type>).
2) I collected all types that the column can fit in and chose the most specific and smallest.
3) Then I detached the table - SET TABLE <table> SOURCE OFF.
4) Then I did the ALTER COLUMN.
5) Lastly, reattach - SET TABLE <table> SOURCE ON.
This way the table ends up with the most fitting type and the caches and indexes work more optimally.
For large tables, though, it could be worth flipping the resulting table into a native CACHED (disk-based) table.
Code coming when I clean it up.

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.