This DDL:
CREATE TABLE example (
my_stamp TIMESTAMP_NTZ NOT NULL DEFAULT CURRENT_TIMESTAMP(0)
)
Yields this error:
SQL compilation error: Default value data type does not match data type for column MY_STAMP
Changing CURRENT_TIMESTAMP(0) to CURRENT_TIMESTAMP makes the error "go away".
Yet, this command returns successfully:
select CURRENT_TIMESTAMP(0), CURRENT_TIMESTAMP;
This would also work, I believe. You just need to cast the output of the function to the same timestamp data type as the my_stamp column:
CREATE TABLE example (
my_stamp TIMESTAMP_NTZ NOT NULL DEFAULT CURRENT_TIMESTAMP(0)::TIMESTAMP_NTZ
)
Related
I have created the following User Defined Function :
CREATE FUNCTION MyTable
(
#dd_YearNo INT,
#txt_WeekNoFrom INT,
#txt_WeekNoTo INT,
#dd_Group VARCHAR(MAX),
#dd_Team VARCHAR(MAX),
#dd_SalesPerson NVARCHAR(MAX)
)
RETURNS TABLE
AS
RETURN
SELECT *
FROM T1 (NOLOCK)
WHERE YearNo IN (#dd_YearNo)
AND (WeekNo BETWEEN #txt_WeekNoFrom AND #txt_WeekNoTo )
AND LEFT(Team,2) IN (#dd_Group)
AND Team IN (#dd_Team)
AND SalesPerson IN(#dd_SalesPerson)
I am using it as a my data set n SSRS like below :
How to map the parameters I created for my SSRS package to this user defined query. This is waht I get since I validate it :
These are the parameters I am using in my SSRS package and I am getting them from different queries :
I get the following error :
Invalid Object MyTable
I have read the link Table options do not contain an option key 'connector'
it said we should set the format.
But My Scene is datagen->hive.
Here's my completed example(it's wrong Now)
drop table if exists datagen;
CREATE TABLE datagen (
f_sequence INT,
f_random INT,
f_random_str STRING,
ts AS localtimestamp,
WATERMARK FOR ts AS ts
) WITH (
'connector' = 'datagen',
-- optional options --
'rows-per-second'='5',
'fields.f_sequence.kind'='sequence',
'fields.f_sequence.start'='1',
'fields.f_sequence.end'='50',-- 这个地方限制了一共会产生的条数
'fields.f_random.min'='1',
'fields.f_random.max'='50',
'fields.f_random_str.length'='10'
);
SET table.sql-dialect=hive;
drop table if exists hive_table;
CREATE TABLE hive_table (
f_sequence INT,
f_random INT,
f_random_str STRING
) PARTITIONED BY (dt STRING, hr STRING, mi STRING) STORED AS parquet TBLPROPERTIES (
'partition.time-extractor.timestamp-pattern'='$dt $hr:$mi:00',
'sink.partition-commit.trigger'='partition-time',
'sink.partition-commit.delay'='1 min',
'sink.partition-commit.policy.kind'='metastore,success-file'
);
Flink SQL> insert into hive_table select f_sequence,f_random,f_random_str ,DATE_FORMAT(ts, 'yyyy-MM-dd'), DATE_FORMAT(ts, 'HH') ,DATE_FORMAT(ts, 'mm') from datagen;
[INFO] Submitting SQL update statement to the cluster...
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: Table options do not contain an option key 'connector' for discovering a connector.
Is the solution from above link suitable for this case?
Need your help,Thanks~!
please use SET table.sql-dialect=default; before call insert into hive_table..., the statement insert into hive_table... using datagen connector which hive dialect should not support.
I have created a not nullable user defined data type using the below script
CREATE TYPE [dbo].[booleano]
FROM TINYINT NOT NULL;
EXECUTE sp_bindefault #defname = N'[dbo].[cero]', #objname = N'[dbo].[booleano]';
It has an bind default value, which is 0.
When I try to add a new column to a table, and this is a not null column it return the following error
ALTER TABLE [dbo].[con_impresion]
ADD [cim_imprime_monto_letras_boo] [dbo].[booleano] NOT NULL;
Rows were detected. The schema update is terminating because data loss might occur.
But if add a default constraint to the new column it returns the following error
ALTER TABLE [dbo].[con_impresion]
ADD [cim_imprime_monto_letras_boo] [dbo].[booleano] DEFAULT 0 NOT NULL;
Column already has a DEFAULT bound to it.
I am facing an problem to set an default value in sql select query
ex: t1.Employee as EmpDeptName
here i need to set an default value so that it returns always the default value
what i tried t1.Employee as EmpDeptName 'ITdept'
But this fails always telling incorrect syntax
If you want to SELECT this value when you call a query,
SELECT 'ITdept' AS EmpDeptName, ...
If you want to use "ITdept" as the default value when the column is empty,
SELECT ISNULL(EmpDeptName, 'ITdept') AS EmpDeptName, ...
If you want to set the column default,
CREATE TABLE t1 (
EmpDeptName <data type> DEFAULT 'ITdept'
);
I have a table called members
CREATE TABLE netcen.mst_member
(
mem_code character varying(8) NOT NULL,
mem_name text NOT NULL,
mem_cnt_code character varying(2) NOT NULL,
mem_brn_code smallint NOT NULL, -- The branch where the member belongs
mem_email character varying(128),
mem_cell character varying(11),
mem_address text,
mem_typ_code smallint NOT NULL,
CONSTRAINT mem_code PRIMARY KEY (mem_code ))
each member type has a different sequence for the member code. i.e for gold members their member codes will be
GLD0091, GLD0092,...
and platinum members codes will be
PLT00020, PLT00021,...
i would like to have the default value for the field mem_code as a dynamic value depending on the member type selected. how can i use a check constraint to implement that??
please help, am using Postgresql 9.1
i have created the following trigger function to construct the string but i still get an error when i insert into the members table as Randy said.
CREATE OR REPLACE FUNCTION netcen.generate_member_code()
RETURNS trigger AS
$BODY$DECLARE
tmp_suffix text :='';
tmp_prefix text :='';
tmp_typecode smallint ;
cur_setting refcursor;
BEGIN
OPEN cur_setting FOR
EXECUTE 'SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type WHERE type_code =' || NEW.mem_typ_code ;
FETCH cur_setting into tmp_suffix,tmp_prefix,tmp_typecode;
CLOSE cur_setting;
NEW.mem_code:=tmp_prefix || to_char(nextval('seq_members_'|| tmp_typecode), 'FM0000000') || tmp_suffix;
END$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION netcen.generate_member_code()
OWNER TO mnoma;
where could i be going wrong?
i get the following error
ERROR: relation "mst_member_type" does not exist
LINE 1: SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type W...
^
QUERY: SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type WHERE typ_code =1
CONTEXT: PL/pgSQL function "generate_member_code" line 7 at OPEN
i think this is a normalization problem.
the codes you provide are derivable from other information - therefore really do not belong as independent columns.
you could just store the type in one column, and the number in another - then on any query where needed append them together to make this combo-code.
if you want to persist this denormalized solution, then you could make a trigger to construct the string on any insert or update.