Snowflake : Facing issues while adding multiple values through insert into values - snowflake-cloud-data-platform

I am trying to add multiple rows in the table in snowflake using "insert into values" statement.
Here is create table statement :
create table table1(col1 float);
I am inserting multiple rows using following command :
insert into table1(col1) values (-3.4E20),(3.4E-20);
I am getting error like
"Numeric value '-340000000000000000000' is not recognized"
On the other hand if I try inserting both the rows separately its getting successful.
Insertion commands :
insert into table1(col1) values (-3.4E20);
insert into table1(col1) values (3.4E-20);
Can you please help me identify the issue with the insert command with multiple rows?
Any suggestions, help will be very helpful.

Expanding on Marcel's answer, this query produces the same error:
select $1
from values (-3.4E20), (3.4E-20);
And this one fixes it:
select $1
from values (-3.4E20::float), (3.4E-20);
As seen in the query, the solution is to add information to the literal number so Snowflake doesn't get confused about possible types.

I'm not sure whether this is related to your problem but maybe it helps finding an answer.
According to docs you have to make sure that the data types of the inserted values are consistent across the rows because the server looks at the data type of the first row as a guide. So... if the datatypes from your first and second values-clause are different (maybe due to some automatically conversion of one of the values above), the combined query will fail. Even if they match the datatype of the table's column!
Link: https://docs.snowflake.com/en/sql-reference/sql/insert.html#multi-row-insert-using-explicitly-specified-values

Related

Dynamic column name in snowflake

I am new to snowflake so please bear with me.
I am trying to do a very simple thing - specify a column name by literal but am getting sql compilation error
insert into MYDB.MYSCHEMA.MYTABLE (identifier('MYCOLUMN')) values (10);
SQL compiler points into unexpected parenthesis before MYCOLUMN. Skipping the word identifier and single qotes works fine.
Just got a response from Snowflake support. Currently "identifier" is only supported for select statements. It is not implemented for inserts for identifying columns. It does work for identifying tables n both select and insert.

SSMS Editing cell unable to insert row - invalid uuid - how to paste a valid uuid into a cell in edit top 200 rows?

In SSMS, trying to add some test data by editing top 200 rows. How do I get a uuid to paste into the cell? I'm trying not to have to write insert statements.
Have tried getting uuids from an online uuid generator - tried all formats from this generator. Reviewing other stack overflow questions seem to relate to programming rather than editing issues with uuids. Tried adding uuid enclosed with single quotes and without single quotes.
unfortunately the field is defined as binary 16, not null.
AFAIK, Enterprise Manager doesn't allow pasting into binary fields.
If you define the column with the correct data type of uniqueidentifier your paste should work just fine.
https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-2017
The fix isn't to use an INSERT statement (although that is a workaround for right now), the fix is to use the correct datatype.
As an added benefit, the uniqueidentifier column won't allow invalid values, while binary will handle any bytes you can jam in there.
The error message says:
You cannot use the results pane to set this field to values other than null
I would presume this means you cannot supply a guid in the grid, you have to leave it null
Does the column have a default value of NewID()? If so, it should fill in itself when you commit the row (focus another row)
If not, try inserting data by writing an INSERT statement:
INSERT INTO table(list,of,columns,except,auto,generated,ones)
VALUES ('list','of','values'...)
Or by selecting/modifying them from elsewhere:
INSERT INTO table(list,of,columns,except,auto,generated,ones)
SELECT mixed,'list','of','values',and,columns
FROM othertable

SSIS comma delimited string in where clause

I am trying to see if there is an easy answer for this. I have done something similar using multiple pick dropdown parameters in SSRS but this appears to be different.
My scenario is this, so maybe there is an even better answer.
I have a production server that I do not want to make any changes to including temp tables or functions. The production server has a table of clients with about 1600 records. I have set up an SSIS package that will allow transfer of data from production to dev based on a clientid. So my sources would have a query similar to Select Field From Table Where ClientId = ?
This works fine. Now I want to load more than one client, based an data in the clients table. It may be Select ClientId From Clients where Field = A and returns multiple ClientIds.
I am able to populate a comma delimited list from an execute sql task to a SSIS variable, so it maybe 1,4,8.
If I change my source query to use ClientId in (?) I get a conversion error.
I have looked at many posts that advocate a temp table or a function which I want to avoid. Select IN using varchar string with comma delimited values
I have contemplated building the entire sql statement into a variable but this don't seem like the right path as I have many tables to query and transfer where using ClientId = ? works well without having to build each individual SQL statement to a variable.
Is there an easy fix I am missing? I will turn my research now to try to find out how I did this in SSRS but I thought that I should try a post here to see if someone has accomplished this before.
I appreciate any info on this, thank you.
EDIT: Key note is that the column on clients is on the dev server, so I cannot just use a select in the where clause as the column does not exist on the production server.
EDIT: I did not mention that I am specifically looking at OLEDB sources mapping a parameter to ? in the sql statement.
EDIT: Narrowing down on this but having trouble relating SSRS and SSIS functionality. In SSRS its called a multi-value parameter in the following link the key line is
WHERE Production.ProductInventory.ProductID IN (#ProductID)
https://msdn.microsoft.com/en-us/library/dn385719(v=sql.110).aspx
This one looks good as well
https://sqlblogcasts.com/blogs/simons/archive/2007/11/22/RS-HowTo---Pass-a-multivalue-parameter-to-a-query-using-IN.aspx
I will keep researching and thank you for the help so far.
I think this sums it up best
This functionality is limited to strictly using embedded SQL.
What SSRS does is transform your SQL column IN (#value) to column IN
(#selectedvalue1,#selectedvalue2) etc.
You need to forget anything you have about the other ways of passing
lists to SQL i.e. building strings etc. and make sure you declare the
data types are correct for the value of your parameter.
You do not need to use the Join(parameters!,",") trick UNLESS
you are passing the list to a stored procedure.
In which case you then need to use some function to turn the delimited
list into a rowset as you have done.
I hope that helps
The core question is if I can get the same functionality in SSIS as in SSRS. It reminds me of macro substitution..
If you dont want to create a function, you can use the following in your t-sql statement.
Declare #ClientIds nvarchar(50) = '123,456'; --<-- Comma delimited list of Client Ids
Select Field
From Table
Where ClientId IN (
SELECT CAST(RTRIM(LTRIM(Split.a.value('.', 'VARCHAR(100)'))) AS INT) ClientIDs
FROM (
SELECT Cast ('<X>'
+ Replace(#ClientIds, ',', '</X><X>')
+ '</X>' AS XML) AS Data
) AS t CROSS APPLY Data.nodes ('/X') AS Split(a)
)

Passing Variable in SSIS

I need some help to pass row value to the other task in SSIS package. Here is my sample query select distinct txnno from tbltxn, what I need is to get distinct txnno from this query and delete records from other table based on this txnno. I think we can pick txxno in some variable in a foreach in a container and pass that recordset value to the query which is used to delete.But I have not done this before, so I need some clues and examples to solve this problem.
Here you go - the documentation includes a link to samples on Codeplex:
http://technet.microsoft.com/en-us/library/cc280492.aspx

Traversing multiple CSV in SQL

I have a SQL Server 2008 database. This database has a stored procedure that will update several records. The ids of these records are stored in a parameter that is passed in via a comma-delimited string. The property values associated with each of these ids are passed in via two other comma-delimited strings. It is assumed that the length (in terms of tokens) and the orders of the values are correct. For instance, the three strings may look like this:
Param1='1,2,3,4,5'
Param2='Bill,Jill,Phil,Will,Jack'
Param3='Smith,Li,Wong,Jos,Dee'
My challenge is, I'm not sure what the best way to actually go about parsing these three CSVs and updating the corresponding records are. I have access to a procedure named ConvertCSVtoTable, which converts a CSV to a temp table of records. So Param1 would return
1
2
3
4
5
after the procedure was called. I thought about a cursor, but then it seems to get really messy.
Can someone tell me/show me, what the best way to address this problem is?
I'd give some thought to reworking the inputs to your procedure. Since you're running SQL 2008, my first choice would be to use a table-valued parameter. My second choice would be to pass the parameters as XML. Your current method, as you already know, is a real headache and is more error prone.
You can use bulk load to insert values to tmp table after that PIVOT them and insert to proper one.

Resources