Re: [GENERAL] SPI_execute error handling

2015-09-07 Thread James Harper
> Hi > > > When I need to solve similar situation, I take a code from plpgsql. > look on function exec_stmt_block. Similar code is in plpgsql_check > https://github.com/okbob/plpgsql_check/blob/master/plpgsql_check.c > Thanks. Got it sorted! James -- Sent via pgsql-general mailing list (pgs

[GENERAL] SPI_execute error handling

2015-09-07 Thread James Harper
The docs for SPI_execute at http://www.postgresql.org/docs/9.4/static/spi.html say: " Note that if a command invoked via SPI fails, then control will not be returned to your procedure. Rather, the transaction or subtransaction in which your procedure executes will be rolled back. (This might se

Re: [GENERAL] SSD Drives

2014-04-04 Thread James Harper
> > It might be tempting to use a consumer-grade SSD due to the significant > cost savings, but the money saved is vapor. They may be OK for a dev > environment, but you *will* pay in downtime in a production environment. > Unlike regular hard drives where the difference between consumer and > ent

[GENERAL] unexpected unnest behaviour

2014-04-01 Thread James Harper
I have a query that blows the arguments in pg_proc out: SELECT pg_proc.oid, UNNEST(pg_proc.proargnames), UNNEST(pg_proc.proargtypes), UNNEST(pg_proc.proargmodes) FROM pg_proc And that works great if all arguments are input arguments, but if two are output arguments, then something unexpected ha

Re: [GENERAL] spi in bgworker

2014-03-22 Thread James Harper
> > James Harper wrote: > > The docs say I'm supposed to call BackgroundWorkerInitializeConnection in > a bgworker and then I can start using spi functions, but they aren't clear on > if > I should call SPI_connect too. > > > > If I call BackgroundWork

[GENERAL] spi in bgworker

2014-03-22 Thread James Harper
The docs say I'm supposed to call BackgroundWorkerInitializeConnection in a bgworker and then I can start using spi functions, but they aren't clear on if I should call SPI_connect too. If I call BackgroundWorkerInitializeConnection and then SPI_execute I get a return code of SPI_ERROR_UNCONNEC

Re: [GENERAL] multiple results from a function

2014-03-03 Thread James Harper
> > James Harper wrote on 03.03.2014 21:10: > > I'm working on an application to accept TDS (Microsoft SQL Server) > > connections and proxy them to postgres. MSSQL does things a little > > differently, for instance in addition to a functions it has stored > > p

Re: [GENERAL] multiple results from a function

2014-03-03 Thread James Harper
> > I'm building against 9.3 at the moment, and my code is external to the > > postgres process and using libpq connections, but I noticed that 9.4 allows > > dynamic backend worker processes which would allow my code to run server > > side and spawn a process for each TDS connection. > > Hm, inte

Re: [GENERAL] multiple results from a function

2014-03-03 Thread James Harper
> > On Thu, Feb 27, 2014 at 6:23 PM, James Harper > wrote: > > I see that I can use PQgetResult to get results from an async query, and > > this > allows for multiple results, presumably when the query is like "SELECT 123, > 456; SELECT 'ABC', 'DEF

[GENERAL] multiple results from a function

2014-02-27 Thread James Harper
I see that I can use PQgetResult to get results from an async query, and this allows for multiple results, presumably when the query is like "SELECT 123, 456; SELECT 'ABC', 'DEF';". Is there a way for a C function, using SPI, to send result sets without waiting for completion and returning a pot

[GENERAL] documentation bug

2014-02-27 Thread James Harper
Just a minor bug in the documentation - http://www.postgresql.org/docs/9.3/static/bgworker.html says that bgw_main takes an argument of void*, but when declared as such gcc -Wall gives a warning of: init.c:59:19: warning: assignment from incompatible pointer type [enabled by default] worker

Re: [GENERAL] execute query from inside C function

2014-02-25 Thread James Harper
> Hello > > you should to use a SPI API > > http://www.postgresql.org/docs/9.3/static/spi.html > > http://www.postgresql.org/docs/9.3/static/spi-spi-exec.html > Yep just found it. I obviously didn't google hard enough. Thanks James -- Sent via pgsql-general mailing list (pgsql-general@post

[GENERAL] execute query from inside C function

2014-02-25 Thread James Harper
I've googled the docs but I can't seem to make a link as to how to execute database queries from inside a C function. I'm used to having a PGconn and using the API around that, but how do I do that from inside a C function (and a bit later on, a language handler?) Thanks James -- Sent via p

Re: [GENERAL] union of types in a different category

2014-02-22 Thread James Harper
> Did you try it? > > postgres=# SELECT '1' UNION SELECT 2; > ?column? > -- > 1 > 2 > (2 rows) > > Now, if I'd done this it would fail: > > postgres=# SELECT '1'::text UNION SELECT 2; > ERROR: UNION types text and integer cannot be matched > LINE 1: SELECT '1'::text UNI

Re: [GENERAL] union of types in a different category

2014-02-22 Thread James Harper
> > I prefer the explicit approach used by Postgres - MYSQL is simpler, but I'd > say > simplistic in this area. While it can automate the cating of tpes/catories of > variable, it doesn't always do it the way I want - so I need to be explicit > anyway. > > In your second use case, which fails -

Re: [GENERAL] union of types in a different category

2014-02-22 Thread James Harper
> > Interestingly - & i'm curious as to why" > > SELECT '1' UNION SELECT 2; > ?column? > -- > 1 > 2 > (2 rows) > > SELECT '1' UNION SELECT 1; > ?column? > -- > 1 > (1 row) > > > I didn't think UNION did an explicit "distinct" - if that is what is > ha

[GENERAL] union of types in a different category

2014-02-22 Thread James Harper
According to clause 3 on http://www.postgresql.org/docs/9.3/static/typeconv-union-case.html regarding union type matching: 3. If the non-unknown inputs are not all of the same type category, fail. So a query "SELECT 1 UNION SELECT 1.1" works because 1 and 1.1 are of the same category, and one

Re: [GENERAL] semi-variable length type

2014-02-20 Thread James Harper
> > James Harper writes: > > I want to make a float(n) type that emulates the mssql float type. The > > storage requirements are documented as 4 bytes for 1 <= n <=24, and 8 > > bytes for 25 <= n <= 53. > > Haven't we got that already? > > r

[GENERAL] semi-variable length type

2014-02-20 Thread James Harper
I want to make a float(n) type that emulates the mssql float type. The storage requirements are documented as 4 bytes for 1 <= n <=24, and 8 bytes for 25 <= n <= 53. If I understand correctly, my options for emulating this in postgres are: 1. declare as variable length. Storage is then 8 bytes (

[GENERAL] oid of Datum

2014-02-19 Thread James Harper
In a postgres C function (CREATE FUNCTION LANGUAGE C), is it possible to get the OID of a parameter and therefore overload a C function? Is there any other way of overloading a C function? Thanks James -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to y

[GENERAL] typmod for custom type

2014-02-16 Thread James Harper
I have created a custom type called my_numeric, which is roughly the same as the existing numeric type. I have declared in, out, typmod_in, and typmod_out functions. I create a table like: CREATE TABLE test (col1 my_numeric(6, 3)); And then do \d test and can see that col1 is declared as (6, 3)

Re: [GENERAL] type aliases

2014-02-15 Thread James Harper
> > You probably should define your domain like this: > >CREATE DOMAIN myvarchar varchar(42); > That's what I thought, so it won't do what I want. I need to be able to set the length at the time of declaration. So suppose I wanted to implement myvarchar in C. In my _in function, how do I

[GENERAL] type aliases

2014-02-14 Thread James Harper
I can create an alias of a type like: CREATE DOMAIN myvarchar varchar; But I can't declare a myvarchar with a variable size, eg "mycolumn myvarchar(42)" and from what I've read this is the way it DOMAIN is supposed to work so I can't do it that way. Is there a way to define myvarchar the way I

[GENERAL] function with different return type depending on parameter?

2014-02-12 Thread James Harper
is it possible to have a function that can return a different type depending on the parameters? Eg (approximately) if param = "one" then return 1 if param = "two" then return "2" if param = "three" then return 3.0 etc I can't see any variant type thanks James -- Sent via pgsql-general m

Re: [GENERAL] implicit cast of empty string to timestamp

2006-02-11 Thread James Harper
Not my application :( > -Original Message- > From: Tom Lane [mailto:[EMAIL PROTECTED] > Sent: Saturday, 11 February 2006 01:59 > To: James Harper > Cc: pgsql-general@postgresql.org > Subject: Re: [GENERAL] implicit cast of empty string to timestamp > > "Ja

Re: [GENERAL] implicit cast of empty string to timestamp

2006-02-10 Thread James Harper
that? Thanks James > -Original Message- > From: [EMAIL PROTECTED] [mailto:pgsql-general- > [EMAIL PROTECTED] On Behalf Of James Harper > Sent: Friday, 10 February 2006 20:23 > To: pgsql-general@postgresql.org > Subject: [GENERAL] implicit cast of empty string to timestamp >

Re: [GENERAL] implicit cast of empty string to timestamp

2006-02-10 Thread James Harper
> am 10.02.2006, um 20:22:57 +1100 mailte James Harper folgendes: > > Is there anything I can do to make postgres allow an implicit cast of an > > empty string to a timestamp, so that a badly behaved application can do: > > > INSERT INTO SomeTable (timestampfield) VA

[GENERAL] implicit cast of empty string to timestamp

2006-02-10 Thread James Harper
Is there anything I can do to make postgres allow an implicit cast of an empty string to a timestamp, so that a badly behaved application can do: INSERT INTO SomeTable (timestampfield) VALUES ('') Where timestampfield is of type typestamp. ? From what I understand of the 'CREATE CAST' command, I

Re: [GENERAL] owner as namespace?

2006-02-08 Thread James Harper
> > Martijn van Oosterhout writes: > > IIRC, the idea of a schema came from Oracle where the schema is the > > username. If you create a schema with the same name as the user what > > you describe above works. ie mydb.james.myview is in the james schema > > in the mydb database. > > Actually tha

[GENERAL] owner as namespace?

2006-02-08 Thread James Harper
Under Microsoft SQL, a fully qualified table name is db.owner.tablename (well actually, linked_server.db.owner.table, but we won't go there :) Under Postgres, you can create schemas to simulate different databases within the one actual database, but as far as I can tell, the owner does not contrib

Re: [GENERAL] Insert into other database

2006-02-08 Thread James Harper
> Hi Fellows, > > I'm wondering if in postgres we can insert a tuple into a table that is > outside of a database (I'm supossed to be connected to database1 and want > to insert a register into a table in database2). > > This question is because I want to update a tables into one database from >

Re: [GENERAL] old style outer joins

2006-02-06 Thread James Harper
> On Mon, Feb 06, 2006 at 09:42:22PM +1100, James Harper wrote: > > I think the answer is no, but can anyone tell me if postgresql supports > > the older (pre sql-92?) style outer join syntax, eg: > > I think you're referring to some kind of non-standard > invente

[GENERAL] old style outer joins

2006-02-06 Thread James Harper
I think the answer is no, but can anyone tell me if postgresql supports the older (pre sql-92?) style outer join syntax, eg: SELECT * FROM a,b WHERE a.pk *= b.fk It doesn't appear to support that exact syntax, which suggests it doesn't know what I'm talking about, but maybe there's a system optio

[GENERAL] plpgsql direct from C?

2006-02-04 Thread James Harper
Is there an API method to be able to execute pl/pgsql (or any other language) code directly from C? Eg (please excuse the line wrapping, and the fact that this doesn't represent a case where this would actually be useful!) result = PQexecPL("plpgsql", "IF $1 = 'xyzzy" THEN SELECT * FROM fnord END

Re: [GENERAL] libpq questions

2006-02-01 Thread James Harper
> On Tue, Jan 31, 2006 at 10:23:54PM +1100, James Harper wrote: > > For the libpq interface: > > > > I need to be able to know if a column in a result from a query is > > nullable or not. From reading the documentation it seems that I can > > obtain the followin

Re: [GENERAL] libpq questions

2006-01-31 Thread James Harper
> > Even if such a query did return a "nullable" flag, plenty of other > metadata would be absent that might be just as interesting from a > schema-viewing standpoint (CHECK, PRIMARY KEY, etc.). A better way > to view the schema is to query the system catalogs or the Information > Schema. I now

[GENERAL] libpq questions

2006-01-31 Thread James Harper
For the libpq interface: I need to be able to know if a column in a result from a query is nullable or not. From reading the documentation it seems that I can obtain the following information: . scan all the rows in the result and see if there exists a null value for each column... . backtrack the

[GENERAL] Transact SQL compatibility layer

2006-01-23 Thread James Harper
Is there such a thing as a translator/proxy that can pretend to be a Microsoft SQL server and proxy all the commands to a PostgreSQL server, and the results back again? Obviously the purpose of it would be to allow an application written for MSSQL Server to work with PostgreSQL without modification