snowflake-cloud-data-platform

Add identity column to existing table in Snowflake?

混江龙づ霸主 提交于 2021-01-28 07:45:06
问题 I have a table "MY_TABLE" in Snowflake that I would like to add an identity column to. I tried ALTER TABLE "MY_TABLE" ADD COLUMN primary_key int IDENTITY(1,1); But this returns SQL compilation error: Cannot add column 'PRIMARY_KEY' with non-constant default to non-empty table 'MY_TABLE'. Is this just not possible in snowflake? To try to get around this limitation, I tried to create a temp version of the table CREATE OR REPLACE TABLE "MY_TABLE_TEMP" LIKE "MY_TABLE" ALTER TABLE "MY_TABLE_TEMP"

Working days between two dates in Snowflake

无人久伴 提交于 2021-01-28 06:10:23
问题 Is there any ways to calculate working days between two dates in snowflake without creating calendar table, only using "datediff" function 回答1: After doing research work on snowflake datediff function, I have found the following conclusions. DATEDIFF(DAY/WEEK, START_DATE, END_DATE) will calculate difference, but the last date will be considered as END_DATE -1. DATEDIFF(WEEK, START_DATE, END_DATE) will count number of Sundays between two dates. By summarizing these two points, I have

Snowflake (LEFT JOIN) LATERAL: Unsupported subquery type cannot be evaluated

旧时模样 提交于 2021-01-24 08:10:38
问题 Lateral Join In a FROM clause, the LATERAL keyword allows an in-line view to reference columns from a table expression that precedes that in-line view. A lateral join behaves more like a correlated subquery than like most JOINs. Let's tweak the code provided in documentation a bit: CREATE TABLE departments (department_id INTEGER, name VARCHAR); CREATE TABLE employees (employee_ID INTEGER, last_name VARCHAR, department_ID INTEGER, project_names ARRAY); INSERT INTO departments (department_ID,

how to add a constant value (1) in an empty column in snowflake-matillion

喜你入骨 提交于 2021-01-07 06:31:33
问题 my table looks like id total avg test_no 1 445 89 2 434 85 3 378 75 4 421 84 I'm working on matillion-snowflake I need my result to look like id total avg test_no 1 445 89 1 2 434 85 1 3 378 75 1 4 421 84 1 回答1: In Snowflake, you would modify the table using: update t set test_no = 1; I assume that Matillion supports this as well. 回答2: Just use a Calculator component and set the value of the calculated column to 1 来源: https://stackoverflow.com/questions/65291812/how-to-add-a-constant-value-1

How can I split a string into character in Snowflake?

℡╲_俬逩灬. 提交于 2021-01-05 07:42:31
问题 I need to split a string like "abc" into individual records, like "a", "b", "c". This should be easy in Snowflake: SPLIT(str, delimiter) But if the delimiter is null, or an empty string I get the full str , and not characters as I expected. 回答1: In addition to Felipe's approach, you could also use a JavaScript UDF: create function TO_CHAR_ARRAY(STR string) returns array language javascript as $$ return STR.split(''); $$; select to_char_array('hello world'); 回答2: Update: SQL UDF create or

Unable to insert data into Snowflake database table using pandas to_sql() method

 ̄綄美尐妖づ 提交于 2021-01-04 05:41:43
问题 I have a database SFOPT_TEST on my Snowflake instance. The database has two schemas AUDITS and PARAMS . The schema AUDITS has a table created like this using SQLAlchemy declarative_base() - class AccountUsageLoginHistory(Base): ''' This model will store the account parameters of the customers instances. ''' __tablename__ = constants.TABLE_ACCOUNT_USAGE_LOGIN_HISTORY __table_args__ = { 'schema' : os.environ.get('SCHEMA_NAME_AUDITS') } id = Column(Integer, Sequence('id_login_history'), primary

Unable to insert data into Snowflake database table using pandas to_sql() method

心已入冬 提交于 2021-01-04 05:40:29
问题 I have a database SFOPT_TEST on my Snowflake instance. The database has two schemas AUDITS and PARAMS . The schema AUDITS has a table created like this using SQLAlchemy declarative_base() - class AccountUsageLoginHistory(Base): ''' This model will store the account parameters of the customers instances. ''' __tablename__ = constants.TABLE_ACCOUNT_USAGE_LOGIN_HISTORY __table_args__ = { 'schema' : os.environ.get('SCHEMA_NAME_AUDITS') } id = Column(Integer, Sequence('id_login_history'), primary

In a Snowflake stored procedures, is there a way to check how many columns are in a resultSet?

筅森魡賤 提交于 2021-01-04 03:16:52
问题 I am working with stored procedures in Snowflake. I want to know how to safely check that there are columns in a resultSet before running getColumnValue() which errors if I try to call it on a non-existent column. If I run this var query = `SELECT * FROM somewhere` var result = snowflake.execute({sqlText: query}); var count = result.getColumnCount(); I get an error saying that getColumnCount is not a function. If I run var query = `SELECT * FROM somewhere` var result = snowflake.execute(

In a Snowflake stored procedures, is there a way to check how many columns are in a resultSet?

。_饼干妹妹 提交于 2021-01-04 03:16:38
问题 I am working with stored procedures in Snowflake. I want to know how to safely check that there are columns in a resultSet before running getColumnValue() which errors if I try to call it on a non-existent column. If I run this var query = `SELECT * FROM somewhere` var result = snowflake.execute({sqlText: query}); var count = result.getColumnCount(); I get an error saying that getColumnCount is not a function. If I run var query = `SELECT * FROM somewhere` var result = snowflake.execute(

In a Snowflake stored procedures, is there a way to check how many columns are in a resultSet?

回眸只為那壹抹淺笑 提交于 2021-01-04 03:13:50
问题 I am working with stored procedures in Snowflake. I want to know how to safely check that there are columns in a resultSet before running getColumnValue() which errors if I try to call it on a non-existent column. If I run this var query = `SELECT * FROM somewhere` var result = snowflake.execute({sqlText: query}); var count = result.getColumnCount(); I get an error saying that getColumnCount is not a function. If I run var query = `SELECT * FROM somewhere` var result = snowflake.execute(