npgsql

Syntax error at or near $1 while trying to alter type in postgreSQL-9.6

£可爱£侵袭症+ 提交于 2021-02-20 03:46:39
问题 I'm trying to add a value to an enumerated type in postgreSQL-9.6, and am having trouble figuring out what I'm doing wrong. var tc = new NpgsqlCommand(@"ALTER TYPE attributeName ADD VALUE IF NOT EXISTS :a", conn); //tc.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Text)); //tc.Parameters[0].Value = "test"; tc.Parameters.AddWithValue("a", NpgsqlDbType.Text, "test"); tc.ExecuteNonQuery(); I tried both the commented out code and the current version, and both resulted in an exception. The

C# enum to postgres enum

社会主义新天地 提交于 2021-02-19 07:53:45
问题 I am currently using postgres enum CREATE TYPE http_action_enum AS ENUM ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'); CREATE TABLE IF NOT EXISTS response ( id UUID PRIMARY KEY, http_action http_action_enum NOT NULL ); But when I using the ef framework to insert to postgres database I keep hit the below error: Exception data: Severity: ERROR SqlState: 42804 MessageText: column "destination" is of type source_dest_enum but expression is of type integer Hint:

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

流过昼夜 提交于 2021-02-17 07:07:21
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

a 夏天 提交于 2021-02-17 07:06:15
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

.netcore控制台->定时任务Quartz

不羁岁月 提交于 2021-02-16 12:26:13
  之前做数据同步时,用过timer、window服务,现在不用那么费事了,可以使用Quartz,并且配置灵活,使用cron表达式配置XML就可以。我用的是3.0.7版本支持.netcore。 首先创建一个.netcore控制台应用程序,添加Quartz、Quartz.Jobs、Quartz.Plugins引用,这里面添加了PostgreSql数据库的连接方法,其它数据库可以做为参考,添加Npgsql、Npgsql.EntityFrameworkCore.PostgreSQL引用,目录结构如下 创建数据库DBContext类 using System; using System.Collections.Generic; using System.Text; using Microsoft.EntityFrameworkCore; namespace QuartzPro.DbContext { public class PostgreDbContext : Microsoft.EntityFrameworkCore.DbContext { private string _conn; public PostgreDbContext(DbContextOptions<PostgreDbContext> options) : base (options) { } public

array binding with Npgsql

瘦欲@ 提交于 2021-02-08 10:14:09
问题 Is there a way to do bulk operations with npgsql like with ODP.NET array binding feature ? I am aware of the Batching/Pipelining/multiple SQL statements in a single command (executing in a single roundtrip) but as far as I understand you can't use it in the same way, with different parameters for every statement. If it can be done, I would be happy if someone could provide an example how to convert the code below to Npgsql. List<dto> listDTO; // list containing up to 1000 dtos OraCommand = db

Using Dapper and Postgresql - citext data type

五迷三道 提交于 2021-02-07 21:49:01
问题 I'm not sure if there is a way to support this, but I'm having trouble getting Dapper to map string parameter values to the Postgresql citext data type as it seems to be using the text type. In particular, I'm trying to call a function that takes in citext parameters - the error I get back is: var c = ConnectionManager<T>.Open(); string sql = @"select * from ""dbo"".""MyFunction""(@schemaName, @tableName);"; var param = new { schemaName = schema, tableName = table }; string insecureSalt = c

Using Dapper and Postgresql - citext data type

雨燕双飞 提交于 2021-02-07 21:48:05
问题 I'm not sure if there is a way to support this, but I'm having trouble getting Dapper to map string parameter values to the Postgresql citext data type as it seems to be using the text type. In particular, I'm trying to call a function that takes in citext parameters - the error I get back is: var c = ConnectionManager<T>.Open(); string sql = @"select * from ""dbo"".""MyFunction""(@schemaName, @tableName);"; var param = new { schemaName = schema, tableName = table }; string insecureSalt = c

Array of composite type as stored procedure input passed by C# Npgsql

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-06 14:00:11
问题 I've read several questions and topics related to the issue but none of them actually helped me to solve my problem and none of them actually were related to C#. And here is the actual problem: I have a Postgre composite type: CREATE TYPE law_relation_update_model AS ( from_celex character varying, from_article character varying, to_celex character varying, to_article character varying, link_ids integer[], to_doc_par_id integer ); And I have a stored procedure that is meant to accept an array

Array of composite type as stored procedure input passed by C# Npgsql

帅比萌擦擦* 提交于 2021-02-06 13:59:54
问题 I've read several questions and topics related to the issue but none of them actually helped me to solve my problem and none of them actually were related to C#. And here is the actual problem: I have a Postgre composite type: CREATE TYPE law_relation_update_model AS ( from_celex character varying, from_article character varying, to_celex character varying, to_article character varying, link_ids integer[], to_doc_par_id integer ); And I have a stored procedure that is meant to accept an array