jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
861 stars 145 forks source link

Table-valued parameter support for postgresql provider #477

Closed mcmikecreations closed 1 year ago

mcmikecreations commented 2 years ago

Describe the feature

I have noticed that the page about the PostgreSQL provider hasn't been updated since 2015. Has this been fixed yet? This is a pretty common feature and I require it in the project I am working on. If not, is there a way around this issue to pass an array of values to a stored function?

Is this feature related to a problem, describe

Here's the code that I use.

SQL

CREATE FUNCTION public.info_insert(
    names text[])
    RETURNS integer
    LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
    order_id integer;
    name text;
BEGIN
    order_id = (SELECT COUNT(*) FROM public.info);
    FOREACH name IN ARRAY names
    LOOP
        INSERT INTO public.info(id, title)
        VALUES (order_id, name);
    order_id = order_id + 1;
    END LOOP;
    RETURN order_id;
END;
$BODY$;

C

PostgreSQLInsightDbProvider.RegisterProvider();
DbConnectionStringBuilder c = new NpgsqlConnectionStringBuilder(connectionString);
IEnumerable<string> names = new string[]{"a","c"};
var result = await c.SingleAsync<int>("info_insert", names);

Error

An exception of type 'System.NotImplementedException' occurred in System.Private.CoreLib.dll but was not handled in user code
Cannot set up the table valued parameter for parameter names.. Have you loaded the provider that supports NpgsqlCommand?
jonwagner commented 2 years ago

TVPs weren't supported with Npgsql 2.0, but it might be possible to fully support them now. I'll take a look.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

mcmikecreations commented 2 years ago

@jonwagner was there any progress on this issue?

mcmikecreations commented 2 years ago

Any updates?

jonwagner commented 1 year ago

PG15 appears to support TVPs (see 38.5.3 here: https://www.postgresql.org/docs/current/xfunc-sql.html#XFUNC-SQL-FUNCTION-ARGUMENTS)

It is unclear if Npgsql supports TVPs. For MSSQLServer, this required database-specific code.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.