Monday, December 9, 2024
HomeGolangInsert Error :" Error pq: syntax error at or close to ","...

Insert Error :” Error pq: syntax error at or close to “,” ” – Getting Assist


I’ve tried every part… [stuck with this one and still need to do a bulk version also].

Anybody see what’s unsuitable.

On the backside is the create Desk:

pmnt is a struct

func (pmnt tPGPayment) SingleInsert(pgdb *pgsql.DB) (err error) {

	ctx, cancelfunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancelfunc()

	sqlStatement := "INSERT INTO public.salespayments (invoicenumber, paydatetime_ltz, paytimestamp_epoc, paid, fintransactionid) VALUES (?, ?, ?, ?, ?)"
	stmt, err := pgdb.PrepareContext(ctx, sqlStatement)
	if err != nil {
		grpcLog.Errorf("PgSql SingleInsert: Error %s when getting ready SQL assertion: `%s`n", err, sqlStatement)
		return err
	}
	defer stmt.Shut()

	_, err = stmt.ExecContext(ctx, pmnt.InvoiceNumber, pmnt.PayDateTime_Ltz, pmnt.PayTimestamp_Epoc, pmnt.Paid, pmnt.FinTransactionID)
	if err != nil {
		grpcLog.Errorf("PgSql SingleInsert: Error %s when inserting row into desk: `%s`n", err, "salespayments")
		return err
	}
	if vGeneral.Debuglevel >= 2 {
		grpcLog.Infoln("PgSql SingleInsert: ttt1 row inserted")
	}
	return nil
}

Error:

2024/09/01 13:38:55 ERROR: PgSql SingleInsert: Error pq: syntax error at or close to "," when getting ready SQL assertion: `INSERT INTO public.salespayments (invoicenumber, paydatetime_ltz, paytimestamp_epoc, paid, fintransactionid) VALUES (?, ?, ?, ?, ?)`
2024/09/01 13:38:55 ERROR: PgSql SingleInsert: Error pq: syntax error at or close to "," when getting ready SQL assertion: `INSERT INTO public.salespayments (invoicenumber, paydatetime_ltz, paytimestamp_epoc, paid, fintransactionid) VALUES (?, ?, ?, ?, ?)`
2024/09/01 13:38:55 ERROR: PgSql SingleInsert: Error pq: syntax error at or close to "," when getting ready SQL assertion: `INSERT INTO public.salespayments (invoicenumber, paydatetime_ltz, paytimestamp_epoc, paid, fintransactionid) VALUES (?, ?, ?, ?, ?)`

Struct Def:

sort TPPayment struct {
	InvoiceNumber     string  `json:"invoiceNumber,omitempty" avro:"invoiceNumber" db:"invoicenumber"`
	PayDateTime_Ltz   string  `json:"payDateTime_Ltz,omitempty" avro:"payDateTime_Ltz" db:"paydatetime_ltz"`
	PayTimestamp_Epoc string  `json:"payTimestamp_Epoc,omitempty" avro:"payTimestamp_Epoc" db:"paytimestamp_epoc"`
	Paid              float64 `json:"paid,omitempty" avro:"paid" db:"paid"`
	FinTransactionID  string  `json:"finTransactionId,omitempty" avro:"finTransactionId" db:"fintransactionid"`
}

Create desk:

CREATE TABLE public.salespayments
(
    invoicenumber VARCHAR(40) NOT NULL,
    paydatetime_ltz VARCHAR,
    paytimestamp_epoc VARCHAR,
    paid DECIMAL(10, 2),
    fintransactionid VARCHAR,
	created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (invoicenumber))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

ALTER TABLE IF EXISTS public.salespayments OWNER to dbadmin;

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments