CREATE TABLE DB2 SQLSTATE: 42601, SQLCODE: -104): DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601 - db2

I am trying to create a DB2 table with the following
CREATE TABLE ACQ_FAH_DEV.fah_balance_ledger
(
"ACTIVE" VARCHAR(10),
INPUT_BY VARCHAR(32),
INPUT_TIME DATE,
AMENDED_BY VARCHAR(32),
AMENDED_TIME DATE,
ENTITY VARCHAR(20),
ACCOUNT_CODE VARCHAR(20),
ACCOUNT_NAME VARCHAR(255),
PORTFOLIO_CODE VARCHAR(100),
OM_LOAD_RUN_ID VARCHAR(128) NOT NULL,    
OM_LOAD_TMST TIMESTAMP(6) NOT NULL,    
BM_BUSINESS_INTERVAL_TYP VARCHAR(20) NOT NULL,
BM_BUSINESS_INTERVAL_TMST TIMESTAMP(6) NOT NULL,    
BM_BUSINESS_INTERVAL_START_END_FLAG VARCHAR(10) NOT NULL,    
SM_SOURCE_SYSTEM_CD VARCHAR(16) NOT NULL,    
OM_UNIQUE_ROW_ID BIGINT NOT NULL,    
OM_USER_ID VARCHAR(100) NOT NULL,    
OM_VERSION_ID SMALLINT NOT NULL
)
ORGANIZE BY COLUMN IN ACQ_FAH_DEV
DISTRIBUTE BY HASH(
ACCOUNT_CODE,
OM_VERSION_ID,
BM_BUSINESS_INTERVAL_TYP
);
but running into this error
(SQLSTATE: 42601, SQLCODE: -104): DB2 SQL Error: SQLCODE=-104,
SQLSTATE=42601, SQLERRMC=(;LOAD_RUN_ID VARCHAR;BINARY, DRIVER=4.26.14
SQLSTATE 42601: A character, token, or clause is invalid or missing.
SQL0104N An unexpected token "(" was found following "LOAD_RUN_ID
VARCHAR". Expected tokens may include: "BINARY".
The error seems innocuous but I am not able to see why this is failing.

For LUW, the tablespace clause should be before the organized clause (I assume IN ACQ_FAH_DEV refers to which tablespace to put the table in). Try:
CREATE TABLE ACQ_FAH_DEV.fah_balance_ledger
(
"ACTIVE" VARCHAR(10),
INPUT_BY VARCHAR(32),
INPUT_TIME DATE,
AMENDED_BY VARCHAR(32),
AMENDED_TIME DATE,
ENTITY VARCHAR(20),
ACCOUNT_CODE VARCHAR(20),
ACCOUNT_NAME VARCHAR(255),
PORTFOLIO_CODE VARCHAR(100),
OM_LOAD_RUN_ID VARCHAR(128) NOT NULL,
OM_LOAD_TMST TIMESTAMP(6) NOT NULL,
BM_BUSINESS_INTERVAL_TYP VARCHAR(20) NOT NULL,
BM_BUSINESS_INTERVAL_TMST TIMESTAMP(6) NOT NULL,
BM_BUSINESS_INTERVAL_START_END_FLAG VARCHAR(10) NOT NULL,
SM_SOURCE_SYSTEM_CD VARCHAR(16) NOT NULL,
OM_UNIQUE_ROW_ID BIGINT NOT NULL,
OM_USER_ID VARCHAR(100) NOT NULL,
OM_VERSION_ID SMALLINT NOT NULL
)
IN ACQ_FAH_DEV
ORGANIZE BY COLUMN
DISTRIBUTE BY HASH(
ACCOUNT_CODE,
OM_VERSION_ID,
BM_BUSINESS_INTERVAL_TYP
);
Documentation for CREATE TABLE statement

Related

whenever i try to create table in mysql

CREATE TABLE HRDATA( SRNO smallint NOT NULL auto_increment, BRANCHNAME varchar(255), EMPLOYEENAME varchar(255), EMPID bigint auto_increment NOT NULL, ADDRESS VARCHAR(255), CITY VARCHAR(255), primary key(SRNO);
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

What is wrong with this insert query for Aurora postgres 10.7?

I'm stumped as to why I'm getting the following error
operator does not exist: character varying = text[]
when the following query is running in production:-
INSERT INTO message_status
(created_datetime,correlation_id,batch_id,entity_type,entity_id,entity_status,entity_message,effective_date)
VALUES
('2020-02-04 10:24:14.291000000','6dc16864-5820-475e-918e-51b15722c08a','34d9c646-9bc2-4389-9789-9c0482ba743e','Benchmark','ABCDEFGH','VALIDATION_ERRORED','{"type":"NO_RESULTS","properties":{}}','2020-01-12');
Not able to reproduce LOCALLY or in DBEAVER. Is there anything obviously wrong with this query? We recently migrated from AWS RDS MySQL to AWS Aurora Postgres
DDL
CREATE TABLE public.message_status (
id serial NOT NULL,
correlation_id varchar(36) NULL,
entity_type varchar(32) NULL,
entity_id varchar(32) NULL,
entity_status varchar(32) NULL,
entity_message text NULL,
effective_date timestamp NOT NULL,
record_count int4 NULL,
created_datetime timestamp NOT NULL DEFAULT CURRENT_DATE,
batch_id varchar(50) NULL,
CONSTRAINT message_status_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
) ;
CREATE INDEX ix_message_status ON public.message_status USING btree (effective_date, entity_type, entity_id, created_datetime) ;
CREATE INDEX ix_message_status_effective_date ON public.message_status USING btree (effective_date) ;
Postgres version = 10.7
pg-promise npm library version = 9.2.1

Postgres error "ERROR: INSERT has more target columns than expressions"

I have the following tables :
CREATE TABLE public.participant_audit
(
participant_audit_id bigint NOT NULL DEFAULT nextval('participant_audit_participant_audit_id_seq'::regclass),
participant_id bigint,
shared_asset_id bigint NOT NULL,
asset_role_type character varying(200) NOT NULL,
user_external_ref_uuid uuid NOT NULL,
user_first_name character varying(200) NOT NULL,
user_last_name character varying(200) NOT NULL,
user_email_address character varying(200) NOT NULL,
deleted_timestamp timestamp(0) with time zone,
row_updated_timestamp timestamp(6) with time zone NOT NULL,
row_created_timestamp timestamp(6) with time zone NOT NULL,
row_created_by_db_user oid NOT NULL,
row_updated_by_db_user oid NOT NULL,
created_by_client uuid,
updated_by_client uuid,
CONSTRAINT participant_audit_pkey PRIMARY KEY (participant_audit_id)
)
WITH (
OIDS=FALSE
);
CREATE TABLE public.participant
(
participant_id bigint NOT NULL DEFAULT nextval('participant_participant_id_seq'::regclass),
shared_asset_id bigint NOT NULL,
asset_role_type_id bigint NOT NULL,
user_external_ref_uuid uuid NOT NULL,
user_first_name character varying(200) NOT NULL,
user_last_name character varying(200) NOT NULL,
user_email_address character varying(200) NOT NULL,
deleted_timestamp timestamp(0) with time zone,
row_updated_timestamp timestamp(6) with time zone NOT NULL,
row_created_timestamp timestamp(6) with time zone NOT NULL,
row_created_by_db_user oid NOT NULL,
row_updated_by_db_user oid NOT NULL,
created_by_client uuid,
updated_by_client uuid,
CONSTRAINT participant_pkey PRIMARY KEY (participant_id),
CONSTRAINT participant_asset_role_type_id_fkey FOREIGN KEY (asset_role_type_id)
REFERENCES public.asset_role_type (asset_role_type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT participant_shared_asset_id_fkey FOREIGN KEY (shared_asset_id)
REFERENCES public.shared_asset (shared_asset_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
And the following TRIGGER FUNCTION:
-- DROP FUNCTION public.participant_audit();
CREATE OR REPLACE FUNCTION public.participant_audit()
RETURNS trigger AS
$BODY$
BEGIN
insert into participant_audit
(participant_audit_id, participant_id , shared_asset_id , asset_role_type , user_external_ref_uuid,
user_first_name , user_last_name , user_email_address , deleted_timestamp, row_updated_timestamp,
row_created_timestamp , row_created_by_db_user , row_updated_by_db_user , created_by_client,
updated_by_client
)
select NEW.* ;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100;
When I execute the following INSERT
INSERT INTO participant (shared_asset_id,asset_role_type_id,
user_external_ref_uuid,user_first_name,user_last_name,
user_email_address,row_created_by_db_user,
row_updated_by_db_user,created_by_client,updated_by_client)
VALUES (1, 1, 'c9d140ad-b0da-4a9d-a898-8719000c7b7b'::uuid , 'john', 'simpson', 'js#gmail.com', 1::oid,1::oid, '53ed670d-f680-4e81-b53d-59b3d487633f'::uuid, '53ed670d-f680-4e81-b53d-59b3d487633f'::uuid);
I get the following error:
ERROR: INSERT has more target columns than expressions LINE 2:
...user , row_updated_by_db_user , created_by_client,updated_by...
^ QUERY: insert into public.participant_audit
(participant_audit_id, participant_id , shared_asset_id , asset_role_type ,
user_external_ref_uuid,user_first_name , user_last_name ,
user_email_address , deleted_timestamp,
row_updated_timestamp,row_created_timestamp , row_created_by_db_user ,
row_updated_by_db_user , created_by_client,updated_by_client)
select NEW.* CONTEXT: PL/pgSQL function participant_audit() line 3 at SQL statement
********** Error **********
ERROR: INSERT has more target columns than expressions SQL state:
42601 Context: PL/pgSQL function participant_audit() line 3 at SQL
statement
How can I fix this issue ??
The problem is in your trigger. Count the columns that you are trying to insert into the audit table here.
insert into participant_audit
(participant_audit_id, participant_id , shared_asset_id , asset_role_type , user_external_ref_uuid,
user_first_name , user_last_name , user_email_address , deleted_timestamp, row_updated_timestamp,
row_created_timestamp , row_created_by_db_user , row_updated_by_db_user , created_by_client,
updated_by_client
)
select NEW.* ;
That's quite a few more than what's contained in NEW because your insert statement has only 10 columns in it. I believe some of your columns maybe taking NULL values. Pass nulls explicitly in the SELECT part of your statement inside the trigger.

column does not exist is postgresql

Here is my sql data.
When I execute this query in postgresql getting some error.
Please help me to correct this. I have no experience in this database.
-- ----------------------------
-- Sequence structure for tuning_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "mainpage"."tuning_id_seq";
CREATE SEQUENCE "mainpage"."tuning_id_seq" INCREMENT 1 START 4000 MAXVALUE 9223372036854775807 MINVALUE 1 CACHE 1;
ALTER TABLE "mainpage"."tuning_id_seq" OWNER TO "postgres";
-- ----------------------------
-- Table structure for tuning
-- ----------------------------
DROP TABLE IF EXISTS "mainpage"."tuning";
CREATE TABLE "mainpage"."tuning" (
"id" int4 NOT NULL DEFAULT nextval("tuning_id_seq"::regclass),
"motor_id" int4,
"speed" int4,
"freetext" varchar(200) COLLATE "default",
"date_create" varchar(30) COLLATE "default",
"date_change" varchar(30) COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "mainpage"."tuning" OWNER TO "postgres";
-- ----------------------------
-- Records of tuning
-- ----------------------------
BEGIN;
INSERT INTO "mainpage"."tuning" VALUES ('1', '1', '0', null, null, null);
INSERT INTO "mainpage"."tuning" VALUES ('2', '2', '0', null, null, null);
INSERT INTO "mainpage"."tuning" VALUES ('3', '3', '0', null, null, null);
COMMIT;
Error
NOTICE: table "tuning" does not exist, skipping
ERROR: column "tuning_id_seq" does not exist
********** Error **********
ERROR: column "tuning_id_seq" does not exist
SQL state: 42703
I think the issue is you need to schema-qualify your sequence name.
e.g.:
CREATE TABLE "mainpage"."tuning" (
"id" int4 NOT NULL DEFAULT nextval("mainpage"."tuning_id_seq"::regclass),
"motor_id" int4,
"speed" int4,
"freetext" varchar(200) COLLATE "default",
"date_create" varchar(30) COLLATE "default",
"date_change" varchar(30) COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "mainpage"."tuning" OWNER TO "postgres";
Without the qualification, Postgres will look for the sequence in the public (e.g. unqualified) schema. (Since you could, in theory, have a sequence by the same name in each schema).

PostgreSQL create table syntax

I'm more a mysql person, but I have to do a db in pg and the following CREATE TABLE keeps generating syntax errors... I just get an error: ERROR: syntax error at or near "(" and error: ERROR: syntax error at or near ")" Googling around didn't give me much help... I'm sure that I'm doing something mysql-esque and that's causing problems... (Note: I did already create the mfseq successfully...)
CREATE TABLE master_file (
mfid INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('mfseq'),
prefix VARCHAR(4),
fname VARCHAR(30) NOT NULL,
lname VARCHAR(80) NOT NULL,
MI varchar(1) NULL,
address1 VARCHAR(200) NOT NULL,
address2 VARCHAR(200),
city VARCHAR(28),
state VARCHAR(2),
zip INT(5),
zip_plus4 INT(4),
mrn VARCHAR(30),
aID INT,
iID INT,
gID VARCHAR(1),
pphone VARCHAR(10);
);
Maybe int -> integer and without size (or numeric) and delete the delimiter at pphone field.
It should not be a semi-colon here: pphone VARCHAR(10);