P
Prisma•12mo ago
beeps

TypedSql Array Parameter for Postgres

I am attempting to use array parameters as inputs to my queries, but when I generate the client I get the following error: Error: SQL documentation parsing: invalid type: 'Int[]' (accepted types are: 'Int', 'BigInt', 'Float', 'Boolean', 'String', 'DateTime', 'Json', 'Bytes', 'Decimal') at '{Int[]} $1:groupIds Array of group IDs to process'. If I don't include the [] - the input parameter is not of an array type. I am using this in two scenarios: one with an ANY() filter in my where clause, and the other as an unnest($1::text[]) for inserting an array
4 Replies
Nurul
Nurul•12mo ago
Writing Type-safe SQL with TypedSQL and Prisma Client | Prisma Docu...
Learn how to use TypedSQL to write fully type-safe SQL queries that are compatible with any SQL console and Prisma Client.
beeps
beepsOP•12mo ago
Hey Nurul - somewhat - here is the full query for the filtering scenario: https://pastebin.com/8bLK33rF The insert scenario is just
-- @param {String[]} $1:scanData String of scan data strings to insert
INSERT INTO scan_staging (scan_data)
SELECT unnest($1::text[]);
-- @param {String[]} $1:scanData String of scan data strings to insert
INSERT INTO scan_staging (scan_data)
SELECT unnest($1::text[]);
Pastebin
-- @param {BigInt} $1:groupIds Array of group IDs to process-- @ret...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Nikolas
Nikolas•5mo ago
What is the solution now @Nurul? How can I specify array type in my SQL-File? The docs doesn't answer this case. It is just saying you can use arrays with ANY($1) in postgres. Using -- @param {String[]} $3:searchTerms at the beginning of my SQL-file leads to this error:
Error: SQL documentation parsing: invalid type: 'String[]' (accepted types are: 'Int', 'BigInt', 'Float', 'Boolean', 'String', 'DateTime', 'Json', 'Bytes', 'Decimal') at '{String[]} $3:searchTerms
Error: SQL documentation parsing: invalid type: 'String[]' (accepted types are: 'Int', 'BigInt', 'Float', 'Boolean', 'String', 'DateTime', 'Json', 'Bytes', 'Decimal') at '{String[]} $3:searchTerms
Nikolas
Nikolas•5mo ago
Marc Hess (@MarcHessDev)
@nikolas_beckel @prisma Omit the type comment for array parameters and let Prisma infer the type automatically.
From Marc Hess (@MarcHessDev)
X
No description

Did you find this page helpful?