Insert Error :" Error pq: syntax error at or near "," "

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

Anyone see what’s wrong.

At the bottom is the create Table:

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 preparing SQL statement: `%s`\n", err, sqlStatement)
		return err
	}
	defer stmt.Close()

	_, 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 table: `%s`\n", err, "salespayments")
		return err
	}
	if vGeneral.Debuglevel >= 2 {
		grpcLog.Infoln("PgSql SingleInsert: \t\t\t1 row inserted")
	}
	return nil
}

Error:

2024/09/01 13:38:55 ERROR: PgSql SingleInsert: Error pq: syntax error at or near "," when preparing SQL statement: `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 near "," when preparing SQL statement: `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 near "," when preparing SQL statement: `INSERT INTO public.salespayments (invoicenumber, paydatetime_ltz, paytimestamp_epoc, paid, fintransactionid) VALUES (?, ?, ?, ?, ?)`

Struct Def:

type 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 table:

CREATE TABLE public.salespayments (
    invoicenumber varchar(40) NOT NULL,
    paydatetime_ltz varchar(32),
    paytimestamp_epoc varchar(14),
    paid decimal(10,2),
    fintransactionid varchar(40),
    created_at timestamptz DEFAULT NOW() NOT NULL,
    PRIMARY KEY (invoicenumber))
TABLESPACE pg_default;

CREATE INDEX salespayments_invoicenumber_idx ON public.salespayments (invoicenumber);

ALTER TABLE IF EXISTS public.salespayments OWNER to dbadmin;

Use $1, $2, … as placeholder for parameters…

interesting enough, i did have it like that, but had other errors at the time that i think distracted me… thinking that was the problem,

thank you.

G

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.