Skip to content

incorrect type for 2d array insertion (go & pgx &postgres) #3992

Open
@jmbit

Description

@jmbit

Version

1.29.0

What happened?

I have a table with a TEXT[][], for which I have both an insert and a select statement. The select statement correctly returns a struct with a [][]string field, but the insert param-struct only has a []string instead.
Schema:

CREATE TABLE IF NOT EXISTS msoffice (
  id BIGSERIAL PRIMARY KEY,
  file_id UUID REFERENCES files (id) ON DELETE CASCADE,
  verdict TEXT DEFAULT 'pending',
  container_format TEXT,
  encrypted BOOLEAN DEFAULT false,
  file_format TEXT,
  vba_macros TEXT,
  xlm_macros TEXT,
  vba_stomping BOOLEAN DEFAULT false,
  nb_autoexec INTEGER,
  nb_iocs INTEGER,
  nb_macros INTEGER,
  nb_suspicious INTEGER,
  olevba_results TEXT[][],
  macros TEXT[][]
);

Statements:

-- name: InsertMSOfficeResults :exec
INSERT INTO msoffice (
  file_id, verdict, container_format, encrypted, file_format, vba_macros, xlm_macros,
  vba_stomping, nb_autoexec, nb_iocs, nb_macros, nb_suspicious, olevba_results, macros
) VALUES (
  $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
);

-- name: GetMSOfficeResults :one
SELECT * FROM msoffice
WHERE file_id = $1
LIMIT 1;

Generated code:

const getMSOfficeResults = `-- name: GetMSOfficeResults :one
SELECT id, file_id, verdict, container_format, encrypted, file_format, vba_macros, xlm_macros, vba_stomping, nb_autoexec, nb_iocs, nb_macros, nb_suspicious, olevba_results, macros FROM msoffice
WHERE file_id = $1
LIMIT 1
`

func (q *Queries) GetMSOfficeResults(ctx context.Context, fileID pgtype.UUID) (Msoffice, error) {
	row := q.db.QueryRow(ctx, getMSOfficeResults, fileID)
	var i Msoffice
	err := row.Scan(
		&i.ID,
		&i.FileID,
		&i.Verdict,
		&i.ContainerFormat,
		&i.Encrypted,
		&i.FileFormat,
		&i.VbaMacros,
		&i.XlmMacros,
		&i.VbaStomping,
		&i.NbAutoexec,
		&i.NbIocs,
		&i.NbMacros,
		&i.NbSuspicious,
		&i.OlevbaResults,
		&i.Macros,
	)
	return i, err
}

const insertMSOfficeResults = `-- name: InsertMSOfficeResults :exec
INSERT INTO msoffice (
  file_id, verdict, container_format, encrypted, file_format, vba_macros, xlm_macros,
  vba_stomping, nb_autoexec, nb_iocs, nb_macros, nb_suspicious, olevba_results, macros
) VALUES (
  $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
)
`

type InsertMSOfficeResultsParams struct {
	FileID          pgtype.UUID
	Verdict         pgtype.Text
	ContainerFormat pgtype.Text
	Encrypted       pgtype.Bool
	FileFormat      pgtype.Text
	VbaMacros       pgtype.Text
	XlmMacros       pgtype.Text
	VbaStomping     pgtype.Bool
	NbAutoexec      pgtype.Int4
	NbIocs          pgtype.Int4
	NbMacros        pgtype.Int4
	NbSuspicious    pgtype.Int4
	OlevbaResults   []string
	Macros          []string
}

func (q *Queries) InsertMSOfficeResults(ctx context.Context, arg InsertMSOfficeResultsParams) error {
	_, err := q.db.Exec(ctx, insertMSOfficeResults,
		arg.FileID,
		arg.Verdict,
		arg.ContainerFormat,
		arg.Encrypted,
		arg.FileFormat,
		arg.VbaMacros,
		arg.XlmMacros,
		arg.VbaStomping,
		arg.NbAutoexec,
		arg.NbIocs,
		arg.NbMacros,
		arg.NbSuspicious,
		arg.OlevbaResults,
		arg.Macros,
	)
	return err
}

Is there a known workaround for this issue?

Relevant log output

Database schema

SQL queries

Configuration

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions