Blog Post by Murat Yaşar


Posted on Monday, March 21, 2011 9:37:59 AM and it has been read 6580 times since then.


Npgsql Data Types And Equivalents

Npgsql supports the following data types:

Postgresql Type

NpgsqlDbType

System.DbType Enum

.Net System Type

int8

Bigint

Int64

Int64

bool

Boolean

Boolean

Boolean

Box, Circle, Line, LSeg, Path, Point, Polygon

Box, Circle, Line, LSeg, Path, Point, Polygon

Object

Object

bytea

Bytea

Binary

Byte[]

date

Date

Date

DateTime, NpgsqlDate

float8

Double

Double

Double

int4

Integer

Int32

Int32

money

Money

Decimal

Decimal

numeric

Numeric

Decimal

Decimal

float4

Real

Single

Single

int2

Smallint

Int16

Int16

text

Text

String

String

time

Time

Time

DateTime, NpgsqlTime

timetz

Time

Time

DateTime, NpgsqlTimeTZ

timestamp

Timestamp

DateTime

DateTime, NpgsqlTimestamp

timestamptz

TimestampTZ

DateTime

DateTime, NpgsqlTimestampTZ

interval

Interval

Object

TimeSpan, NpgsqlInterval

varchar

Varchar

String

String

inet

Inet

Object

NpgsqlInet, IPAddress
(there is an implicity cast operator to convert NpgsqlInet objects into IPAddress if you need to use IPAddress and have only NpgsqlInet)

bit

Bit

Boolean

Boolean, Int32
(If you use an Int32 value, odd values will be translated to bit 1 and even values to bit 0)

uuid

Uuid

Guid

Guid

array

Array

Object

Array
In order to explicitly use array type, specify NpgsqlDbType as an 'OR'ed type: NpgsqlDbType.Array | NpgsqlDbType.Integer for an array of Int32 for example.

This table has been taken from the following site.

Npgsql Projects Postgresql


(In order to use this feature, you have to register.)


  • szamora
    szamora | Reply
    Saturday, March 10, 2012 10:21:41 PM

    Reading a Polygon item from vb.net

    Imports Npgsql
    Imports NpgsqlTypes
    .
    .
    .
    Dim Vertexes As NpgsqlPolygon
    Dim Point As NpgsqlPoint
    Dim PGConn As NpgsqlConnection
    PGConn = New NpgsqlConnection("Server=yourserver;Port=yourport;User Id=youruser;Password=yourpass;Database=yourDB;")
    PGConn.Open()
     
    ' Read a row with a Polygon item
    Dim comando As New NpgsqlCommand("select * from yourtable where yourcolumnname = 'gggg'", PGConn)
    Dim PGReader As NpgsqlDataReader
    
    PGReader = comando.ExecuteReader() Try
    
       If (PGReader.HasRows()) Then
          PGReader.Read()       ' The Polygon item has the index 2 in my table
          Vertexes = PGReader.Item(2)       ' Example about how to get a vertex (x,y point) from the polygon item
    
          Point = Vertexes.Item(8)
          MsgBox("X=" + Point.X.ToString() + ",  Y=" + Point.Y.ToString()) Catch ex As Exception
    
          MsgBox(ex.Message)
    Finally
          If Not (PGReader.IsClosed()) Then
              PGReader.Close()
          End If
          comando.Dispose()
    End Try

     


  • Murat Yasar
    Murat Yasar | Reply
    Sunday, March 11, 2012 8:13:52 AM

    A good sample. Thanks.

Tag Related Blog Entries

Scratching Beneath the Surface

Friday, March 11, 2022 0   1716  

Compare Tables Row By Row in PostgreSQL

Sunday, June 21, 2015 2   13841  

Some Helpful Links For Software Developers

Saturday, April 28, 2012 0   7817  

Show All Functions and Views In PostgreSQL By Using Select Statement And Querying pgCatalog

Saturday, February 18, 2012 0   2440  

DataBinding GridView In Asp.NET Application By Using PostgreSQL as DataSource

Sunday, October 10, 2010 0   11975  

PostgreSQL - PL/pgSQL Little Code Snippets

Friday, October 08, 2010 3   4737  

PostgreSQL 8.4.4 Data Types

Monday, September 27, 2010 0   2640