Error during copy command in Postgres - sql

I'm trying to insert data into my table in Postgres with the COPY command and I had the following error:
ERROR: extra data after last expected column
There is my COPY command :
copy basic_data_cs from '/data/tmp/basic_data.csv' delimiter ';' header csv;
There is my table structure :
CREATE FOREIGN TABLE basic_data_cs
( oid4 BIGINT , oid3 BIGINT , date_creation date , date_modif date , id_princ text , nb_ref INTEGER , coobox INTEGER , otype_bin INTEGER , ra REAL , ra_prec SMALLINT , dec REAL , dec_prec SMALLINT , coo_err_maja FLOAT , coo_err_maja_prec SMALLINT , coo_err_mina FLOAT , coo_err_mina_prec SMALLINT , coo_err_angle SMALLINT , coo_qual TEXT , coo_wavelength TEXT , coo_bibcode TEXT , pmra REAL , pmra_prec SMALLINT , pmdec REAL , pmdec_prec SMALLINT , pm_err_maja FLOAT , pm_err_maja_prec SMALLINT , pm_err_mina FLOAT , pm_err_mina_prec SMALLINT , pm_err_angle SMALLINT , pm_qual text , pm_bibcode text , plx_value REAL , plx_prec SMALLINT , plx_error FLOAT , plx_error_prec SMALLINT , plx_qual TEXT , plx_bibcode TEXT , rvz_type TEXT , rvz_radvel REAL , rvz_radvel_prec SMALLINT , rvz_redshift REAL , rvz_redshift_prec SMALLINT , rvz_error FLOAT , rvz_error_prec SMALLINT , rvz_qual TEXT , rvz_nature TEXT , rvz_wavelength TEXT , rvz_bibcode TEXT , sp_type TEXT , sp_type_bin BIGINT , sp_qual text , sp_nature text , sp_bibcode text , morph_type text , morph_type_bin INTEGER , morph_qual text , morph_bibcode text , galdim_majaxis FLOAT , galdim_majaxis_prec SMALLINT , galdim_minaxis FLOAT , galdim_minaxis_prec SMALLINT , galdim_angle SMALLINT , galdim_incl SMALLINT , galdim_qual text , galdim_wavelength text , galdim_bibcode text , nb_parents INTEGER , nb_children INTEGER , nb_siblings INTEGER , id_princ_select text , hpx BIGINT , otype text , vlsr REAL , vlsr_prec SMALLINT , vlsr_error REAL , vlsr_error_prec SMALLINT , vlsr_wavelength text , vlsr_bibcode text) server cstore_server;
And there is a line from my csv file :
10396425;;2016-08-02;2016-08-02;SDSS J001954.03+025717.0;1;11278;-14680064;4.975139;7;2.954735;7;;-1;;-1;32767;C;O;2014A&A...563A..54P;;;;;;;;;;;;;;;;;;z;263064.159868091;0;2.9147;4;0.0003;4;C;s;O;2014A&A...563A..54P;;;;;;;;;;;;;;;;;;;;;;;(0.0868325562943782 , 0.0515698542739147);4635816;QSO;;;;;;;;;;
This command worked for an another 'classic' table with the same CSV file and the same command.

This would be because , your table contains 78 columns and your csv delimited file has 82 entries.

Either you get a new csv with same columns as table or you can try
check the top answer from there

Related

Assigning a HANA hierarchy query to a table variable leads to inconsistent results

Context
I want to use the HANA HIERARCHY_TEMPORAL function to work on a SAP KNVH hierarchy with time intervals ;
When simply used in a SELECT query, this works fine ;
When otherwise using the very same query but assigning it to a table variable, the result is inconsistent.
My problem
This anonymous block works just fine using an HANA HIERARCHY_TEMPORAL function :
DO
BEGIN
DECLARE hierarchy_type CHAR(1);
DECLARE valid_from CHAR(8);
DECLARE valid_until CHAR(8);
hierarchy_type = 'A' ;
valid_from = '20211201' ;
valid_until = '20211201' ;
SELECT
HIERARCHY_RANK ,
HIERARCHY_TREE_SIZE ,
HIERARCHY_PARENT_RANK ,
HIERARCHY_ROOT_RANK ,
HIERARCHY_LEVEL ,
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR ,
HKUNNR ,
node_id ,
parent_id ,
valid_from ,
valid_until ,
DATAB ,
DATBI
FROM HIERARCHY_TEMPORAL (
SOURCE
(
SELECT
HIERARCHY_COMPOSITE_ID(
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR
) AS node_id ,
CASE HKUNNR
WHEN '' THEN NULL
ELSE HIERARCHY_COMPOSITE_ID(
HITYP ,
HVKORG ,
HVTWEG ,
HSPART ,
HKUNNR
)
END AS parent_id ,
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR ,
HKUNNR ,
DATAB AS valid_from ,
DATBI AS valid_until ,
DATAB ,
DATBI
FROM SAPKTP. KNVH
WHERE
KNVH. HITYP = :hierarchy_type
)
VALID FROM :valid_from UNTIL :valid_until
);
END;
But assigning the very same block and querying the table variable afterwards leads to inconsistent results :
DO
BEGIN
DECLARE tbl_CLIENT_HIERARCHY TABLE (
HIERARCHY_RANK CHAR ,
HIERARCHY_TREE_SIZE CHAR ,
HIERARCHY_PARENT_RANK CHAR ,
HIERARCHY_ROOT_RANK CHAR ,
HIERARCHY_LEVEL CHAR ,
HITYP CHAR ,
VKORG CHAR ,
VTWEG CHAR ,
SPART CHAR ,
KUNNR CHAR ,
HKUNNR CHAR ,
node_id CHAR ,
parent_id CHAR ,
valid_from CHAR ,
valid_until CHAR ,
DATAB CHAR ,
DATBI CHAR
);
DECLARE hierarchy_type CHAR(1);
DECLARE valid_from CHAR(8);
DECLARE valid_until CHAR(8);
hierarchy_type = 'A' ;
valid_from = '20211201' ;
valid_until = '20211201' ;
tbl_CLIENT_HIERARCHY =
SELECT
HIERARCHY_RANK ,
HIERARCHY_TREE_SIZE ,
HIERARCHY_PARENT_RANK ,
HIERARCHY_ROOT_RANK ,
HIERARCHY_LEVEL ,
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR ,
HKUNNR ,
node_id ,
parent_id ,
valid_from ,
valid_until ,
DATAB ,
DATBI
FROM HIERARCHY_TEMPORAL (
SOURCE
(
SELECT
HIERARCHY_COMPOSITE_ID(
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR
) AS node_id ,
CASE HKUNNR
WHEN '' THEN NULL
ELSE HIERARCHY_COMPOSITE_ID(
HITYP ,
HVKORG ,
HVTWEG ,
HSPART ,
HKUNNR
)
END AS parent_id ,
HITYP ,
VKORG ,
VTWEG ,
SPART ,
KUNNR ,
HKUNNR ,
DATAB AS valid_from ,
DATBI AS valid_until ,
DATAB ,
DATBI
FROM SAPKTP. KNVH
WHERE
KNVH. HITYP = :hierarchy_type
)
VALID FROM :valid_from UNTIL :valid_until
);
SELECT TOP 10 * FROM :tbl_CLIENT_HIERARCHY;
END;
Does anybody know why?
Thank you for your help.
One potential reason could be the missing SIBLING ORDER BY clause (cf. https://help.sap.com/viewer/09f734c2169c4661b1aa15c00022ab21/2021_3_QRC/en-US/c44d60a76342456f91cb51054915a32e.html ). Without a stable sibling order, SAP HANA hierarchy generator functions may behave non-deterministically.
Actually the problem had nothing to do with HANA hierarchy : I simply didn't precise between brackets the number of characters for the declared table variable, which is then interpreted as CHAR(1), leading to the strange extraction result!

multiple BLOB file insertion in oracle using SQLdeveloper

I want to insert Multiple BLOB file at once ​​in "USER_PROFILE" table using loop by procedure/function.
Working on Oracle DB using SQLdeveloper
BLOB Files:
user.resetpassword.email.body.html
password.expiry.notification.email.html
password.expiry.notification.subject.txt
user.resetpassword.email.subject.txt
BLOB FILE DIRECTORY : U_PROFILE
BLOB column name : PROP_VALUE
Unique key : PROP_KEY (This column naming conventions will be same with BLOB file names)
CREATE TABLE "USER_PROFILE" (
"USER_PROFILE_PID" VARCHAR2(40 BYTE)
, "PROP_KEY" VARCHAR2(100 BYTE)
, "PROP_VALUE" BLOB
, "MODIFIED_DTS" DATE
, "BUILD_VERSION" VARCHAR2(100 BYTE)
, "DESCRIPTION" VARCHAR2(4000 BYTE)
)
​;
INSERT INTO user_profile (
user_profile_pid
, prop_key
, modified_dts
, build_version
, description
) VALUES (
'CTP-1000'
, 'password.expiry.notification.email'
, NULL
, '1.2'
, 'User Account Expiry notification'
);
INSERT INTO user_profile (
user_profile_pid
, prop_key
, modified_dts
, build_version
, description
) VALUES (
'CTP-1001'
, 'password.expiry.notification.subject'
, NULL
, '1.2'
, 'User Account Expiry notification subject'
);

I am inserting excel sheet bulk data into a sql database table, now i need to split the table into multiple tables by using stored procedure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
SELECT [myaccount_firstname] ,
[myaccount_lastname] ,
[myaccount_email] ,
[myaccount_mobile_no] ,
[myaccount_workphone] ,
[myaccount_street_1] ,
[myaccount_street_2] ,
[myaccount_city] ,
[myaccount_state] ,
[myaccount_zipcode] ,
[myaccount_country] ,
[business_setup_business_name] ,
[business_setup_fein_reg_id] ,
[business_setup_duns] ,
[business_setup_street_1] ,
[business_setup_street_2] ,
[business_setup_city] ,
[business_setup_state] ,
[business_setup_zipcode] ,
[business_setup_country] ,
[business_setup_businessphone] ,
[business_setup_businessfax] ,
[business_setup_emailid] ,
[business_setup_website] ,
[business_setup_primary_firstname] ,
[business_setup_primary_lastname] ,
[business_setup_primary_email] ,
[business_setup_primary_mobile] ,
[business_setup_primary_workphone] ,
[business_setup_secondary_firstname] ,
[business_setup_secondary_lastname] ,
[business_setup_secondary_email] ,
[business_setup_secondary_mobile] ,
[business_setup_secondary_workphone] ,
[business_setup_pay_via] ,
[business_setup_paypal_id] ,
[business_info_short_description] ,
[business_info_long_description] ,
[business_info_hours_Sunday] ,
[business_info_hours_Monday] ,
[business_info_hours_Tuesday] ,
[business_info_hours_wednesday] ,
[business_info_hours_Thursday] ,
[business_info_hours_Friday] ,
[business_info_hours_Saturday] ,
[business_info_starttime] ,
[business_info_endtime] ,
[business_info_webonly] ,
[business_info_telephoneonly] ,
[business_info_appointmentonly] ,
[business_info_speciality_Acupuncture] ,
[business_info_speciality_Chiropractor] ,
[business_info_speciality_Conventional] ,
[business_info_speciality_Dentist] ,
[business_info_speciality_ElderlyCare] ,
[business_info_speciality_EyeCare] ,
[business_info_speciality_General] ,
[business_info_speciality_HealthCoach] ,
[business_info_speciality_Homeopathy] ,
[business_info_speciality_LifeCoach] ,
[business_info_speciality_Meditation] ,
[business_info_speciality_MyofacialTherapy] ,
[business_info_speciality_Naturopathy] ,
[business_info_speciality_NutritionHealthyCooking] ,
[business_info_speciality_Pilates] ,
[business_info_speciality_WellnessCenter] ,
[business_info_speciality_Yoga] ,
[subscription_type]
FROM [bulk_data]
This is main table from this, i need to split the data to three tables
myaccount
business_setup
business_info
I assume that you want to dumb the data from bulk_data to myaccount table, business_setup table and business_info table.
if so,
Assumptions :
- Column names with prefix myaccount_ belongs to myaccount table
- Column names with prefix business_setup belongs to business_setup table
- Column names with prefix business_info belongs to business_info table
- complete data from [bulk_data] needs to be dump in to above tables
Limitations:
- please don't forget to include not-null columns of tables in select list
- handle foreign key columns (if exists) by yourself
-- EXEC Data_Migration
CREATE PROCEDURE Data_Migration
AS
BEGIN
/* before you execute this, make sure to include all not null column names in select list */
INSERT INTO myaccount ([myaccount_firstname] ,
[myaccount_lastname] ,
[myaccount_email] ,
[myaccount_mobile_no] ,
[myaccount_workphone] ,
[myaccount_street_1] ,
[myaccount_street_2] ,
[myaccount_city] ,
[myaccount_state] ,
[myaccount_zipcode] ,
[myaccount_country])
SELECT
[myaccount_firstname] ,
[myaccount_lastname] ,
[myaccount_email] ,
[myaccount_mobile_no] ,
[myaccount_workphone] ,
[myaccount_street_1] ,
[myaccount_street_2] ,
[myaccount_city] ,
[myaccount_state] ,
[myaccount_zipcode] ,
[myaccount_country]
FROM [bulk_data]
/* before you execute this, make sure to include all not null column names in select list */
INSERT INTO business_setup ([business_setup_business_name] ,
[business_setup_fein_reg_id] ,
[business_setup_duns] ,
[business_setup_street_1] ,
[business_setup_street_2] ,
[business_setup_city] ,
[business_setup_state] ,
[business_setup_zipcode] ,
[business_setup_country] ,
[business_setup_businessphone] ,
[business_setup_businessfax] ,
[business_setup_emailid] ,
[business_setup_website] ,
[business_setup_primary_firstname] ,
[business_setup_primary_lastname] ,
[business_setup_primary_email] ,
[business_setup_primary_mobile] ,
[business_setup_primary_workphone] ,
[business_setup_secondary_firstname] ,
[business_setup_secondary_lastname] ,
[business_setup_secondary_email] ,
[business_setup_secondary_mobile] ,
[business_setup_secondary_workphone] ,
[business_setup_pay_via] ,
[business_setup_paypal_id] ,)
SELECT
[business_setup_business_name] ,
[business_setup_fein_reg_id] ,
[business_setup_duns] ,
[business_setup_street_1] ,
[business_setup_street_2] ,
[business_setup_city] ,
[business_setup_state] ,
[business_setup_zipcode] ,
[business_setup_country] ,
[business_setup_businessphone] ,
[business_setup_businessfax] ,
[business_setup_emailid] ,
[business_setup_website] ,
[business_setup_primary_firstname] ,
[business_setup_primary_lastname] ,
[business_setup_primary_email] ,
[business_setup_primary_mobile] ,
[business_setup_primary_workphone] ,
[business_setup_secondary_firstname] ,
[business_setup_secondary_lastname] ,
[business_setup_secondary_email] ,
[business_setup_secondary_mobile] ,
[business_setup_secondary_workphone] ,
[business_setup_pay_via] ,
[business_setup_paypal_id] ,
FROM [bulk_data]
/*
before you execute this, make sure to include all not null column names in select list
I assume [subscription_type] exists in business_info table
*/
INSERT INTO business_info ([business_info_short_description] ,
[business_info_long_description] ,
[business_info_hours_Sunday] ,
[business_info_hours_Monday] ,
[business_info_hours_Tuesday] ,
[business_info_hours_wednesday] ,
[business_info_hours_Thursday] ,
[business_info_hours_Friday] ,
[business_info_hours_Saturday] ,
[business_info_starttime] ,
[business_info_endtime] ,
[business_info_webonly] ,
[business_info_telephoneonly] ,
[business_info_appointmentonly] ,
[business_info_speciality_Acupuncture] ,
[business_info_speciality_Chiropractor] ,
[business_info_speciality_Conventional] ,
[business_info_speciality_Dentist] ,
[business_info_speciality_ElderlyCare] ,
[business_info_speciality_EyeCare] ,
[business_info_speciality_General] ,
[business_info_speciality_HealthCoach] ,
[business_info_speciality_Homeopathy] ,
[business_info_speciality_LifeCoach] ,
[business_info_speciality_Meditation] ,
[business_info_speciality_MyofacialTherapy] ,
[business_info_speciality_Naturopathy] ,
[business_info_speciality_NutritionHealthyCooking] ,
[business_info_speciality_Pilates] ,
[business_info_speciality_WellnessCenter] ,
[business_info_speciality_Yoga] ,
[subscription_type])
SELECT
[business_info_short_description] ,
[business_info_long_description] ,
[business_info_hours_Sunday] ,
[business_info_hours_Monday] ,
[business_info_hours_Tuesday] ,
[business_info_hours_wednesday] ,
[business_info_hours_Thursday] ,
[business_info_hours_Friday] ,
[business_info_hours_Saturday] ,
[business_info_starttime] ,
[business_info_endtime] ,
[business_info_webonly] ,
[business_info_telephoneonly] ,
[business_info_appointmentonly] ,
[business_info_speciality_Acupuncture] ,
[business_info_speciality_Chiropractor] ,
[business_info_speciality_Conventional] ,
[business_info_speciality_Dentist] ,
[business_info_speciality_ElderlyCare] ,
[business_info_speciality_EyeCare] ,
[business_info_speciality_General] ,
[business_info_speciality_HealthCoach] ,
[business_info_speciality_Homeopathy] ,
[business_info_speciality_LifeCoach] ,
[business_info_speciality_Meditation] ,
[business_info_speciality_MyofacialTherapy] ,
[business_info_speciality_Naturopathy] ,
[business_info_speciality_NutritionHealthyCooking] ,
[business_info_speciality_Pilates] ,
[business_info_speciality_WellnessCenter] ,
[business_info_speciality_Yoga] ,
[subscription_type]
FROM [bulk_data]
END

Trouble with OUTPUT statement. Incorrect Syntax

I am trying to update a data set based on one conditional and then retrieving all the updated rows. VS keeps telling me there is an incorrect syntax error near my OUTPUT clause but I do not see anything wrong. I am just trying to figure out how to use "OUTPUT" so this may be a very stupid mistake I am making but failing to see.
What is wrong (syntactically) with this OUTPUT clause?
CREATE PROCEDURE [dbo].[GetInitialSessionNotifications]
#CurrentSessionId bigint
AS
DECLARE #tempTable table(
id bigint NOT NULL,
[Type] nvarchar,
DocumentCommentID bigint,
AnnouncmentID int,
EventID int,
MeetingID int,
[Read] bit,
RecieverId int,
AnnouncmentCommentId bigint,
EventCommentId bigint,
MeetingCommentId bigint,
DateAndTime DateTime);
UPDATE Notifications SET SessionId = #CurrentSessionId
WHERE SessionId != #CurrentSessionId
OUTPUT INSERTED.id,
INSERTED.[Type],
INSERTED.DocumentCommentID,
INSERTED.AnnouncmentID,
INSERTED.EventID,
INSERTED.MeetingID,
INSERTED.[Read],
INSERTED.RecieverId,
INSERTED.AnnouncmentCommentId,
INSERTED.EventCommentId,
INSERTED.MeetingCommentId,
INSERTED.DateAndTime
INTO #tempTable;
SELECT id, [Type], DocumentCommentId, AnnouncmentID, EventID, MeetingID,
[Read], RecieverId, AnnouncmentCommentId, EventCommentId, MeetingCommentId, DateAndTime
FROM #tempTable;
RETURN 0
Try this one -
CREATE PROCEDURE [dbo].[GetInitialSessionNotifications]
#CurrentSessionId BIGINT
AS BEGIN
DECLARE #tempTable TABLE
(
id BIGINT NOT NULL ,
[Type] NVARCHAR ,
DocumentCommentID BIGINT ,
AnnouncmentID INT ,
EventID INT ,
MeetingID INT ,
[Read] BIT ,
RecieverId INT ,
AnnouncmentCommentId BIGINT ,
EventCommentId BIGINT ,
MeetingCommentId BIGINT ,
DateAndTime DATETIME
)
UPDATE Notifications
SET SessionId = #CurrentSessionId
OUTPUT
INSERTED.id ,
INSERTED.[Type] ,
INSERTED.DocumentCommentID ,
INSERTED.AnnouncmentID ,
INSERTED.EventID ,
INSERTED.MeetingID ,
INSERTED.[Read] ,
INSERTED.RecieverId ,
INSERTED.AnnouncmentCommentId ,
INSERTED.EventCommentId ,
INSERTED.MeetingCommentId ,
INSERTED.DateAndTime
INTO #tempTable
WHERE SessionId != #CurrentSessionId
SELECT id ,
[Type] ,
DocumentCommentId ,
AnnouncmentID ,
EventID ,
MeetingID ,
[Read] ,
RecieverId ,
AnnouncmentCommentId ,
EventCommentId ,
MeetingCommentId ,
DateAndTime
FROM #tempTable;
END

SQL stored procedure not grouping rows together

I have the below code. It basically takes values from a spreadsheet loaded in by an asp.net upload control. A document number is automatically assigned. I put the data into a temp table, and then select and insert the data from the temp table into my actual database table. The data is group so that it takes the minimum doc number, and date column (the ONLY columns that are different for the data). The data loads fine but for some reason it does not get grouped. Does anyone see any problems with the query itself?
CREATE Procedure dbo.temptable
(
#DocumentBranchPlant varchar(12)
, #DocumentType varchar(2)
, #DEANumber varchar(9)
, #DebitMemo varchar(25)
, #DebitTotal float
, #ErrorOverRide bit
, #OnHold bit
, #LastModifiedUser varchar(50)
, #ResubmissionCode char(2)
, #DocumentNumber float out
)
AS
begin
declare #TransmissionDate datetime
declare #JulianTransmissionDate numeric(18,0)
declare #ShipTo float
declare #CustomerName varchar(40)
Set #DocumentNumber = scope_identity()
set #TransmissionDate = getdate()
set #JulianTransmissionDate =getdate()
DECLARE #cb table
( DocumentBranchPlant char(12)
, DocumentNumber float
, DocumentType char(2)
, JulianTransmissionDate numeric(18,0)
, TransmissionDate datetime
, DEANumber varchar(9)
, ShipTo float
, DebitMemo char(25)
, DebitTotal float
, CustomerName varchar(40)
, ErrorOverRide bit
, EntryComplete bit
, OnHold bit
, ManualEntry bit
, LastModifiedUser varchar(50)
, LastModifiedDate datetime
, ResubmissionCode char(2))
INSERT INTO #cb
( DocumentBranchPlant
, DocumentNumber
, DocumentType
, JulianTransmissionDate
, TransmissionDate
, DEANumber
, ShipTo
, DebitMemo
, DebitTotal
, CustomerName
, ErrorOverRide
, EntryComplete
, OnHold
, ManualEntry
, LastModifiedUser
, LastModifiedDate
, ResubmissionCode)
VALUES
( #DocumentBranchPlant
, #DocumentNumber
, #DocumentType
, #JulianTransmissionDate
, #TransmissionDate
, #DEANumber
, #ShipTo
, #DebitMemo
, #DebitTotal
, #CustomerName
, #ErrorOverRide
, 0
, #OnHold
, 1
, #LastModifiedUser
, getdate()
, #ResubmissionCode)
INSERT INTO dbo.CbTempTable
( DocumentBranchPlant
, DocumentNumber
, DocumentType
, JulianTransmissionDate
, TransmissionDate
, DEANumber
, ShipTo
, DebitMemo
, DebitTotal
, CustomerName
, ErrorOverRide
, EntryComplete
, OnHold
, ManualEntry
, LastModifiedUser
, LastModifiedDate
, ResubmissionCode)
SELECT
DocumentBranchPlant
, min(DocumentNumber)
, DocumentType
, JulianTransmissionDate
, min(TransmissionDate)
, DEANumber
, ShipTo
, DebitMemo
, DebitTotal
, CustomerName
, ErrorOverRide
, EntryComplete
, OnHold
, ManualEntry
, LastModifiedUser
, min(LastModifiedDate)
, ResubmissionCode
FROM #cb
GROUP BY
DocumentBranchPlant
, DocumentType
, JulianTransmissionDate
, DEANumber
, ShipTo
, DebitMemo
, DebitTotal
, CustomerName
, ErrorOverRide
, EntryComplete
, OnHold
, ManualEntry
, LastModifiedUser
, ResubmissionCode