Re: [GENERAL] C Function Question

2009-07-28 Thread Albe Laurenz
Terry Lee Tucker wrote:
 Does anyone know if a function written in C and linked into the backend in a 
 shared library with a statically declared structure, maintain that data for 
 the life of the backend process such that, when the function is called again, 
 the structure data is intact?
 
 Thanks for any insight anyone can give...

Yes, that should work.

Yours,
Laurenz Albe

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C Function Question

2009-07-28 Thread Terry Lee Tucker
On Tuesday 28 July 2009 03:22, Albe Laurenz wrote:
 Terry Lee Tucker wrote:
  Does anyone know if a function written in C and linked into the backend
  in a shared library with a statically declared structure, maintain that
  data for the life of the backend process such that, when the function is
  called again, the structure data is intact?
 
  Thanks for any insight anyone can give...

 Yes, that should work.

 Yours,
 Laurenz Albe

Thanks for the reply Laurenze. I put together a small test case scenario and, 
indeed, it does work as I had hoped and as you indicated.

Thanks for the help...
-- 

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] C Function Question

2009-07-27 Thread Terry Lee Tucker
Greetings:

Does anyone know if a function written in C and linked into the backend in a 
shared library with a statically declared structure, maintain that data for 
the life of the backend process such that, when the function is called again, 
the structure data is intact?

Thanks for any insight anyone can give...
-- 

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-04 Thread Gregory Stark
Tom Lane t...@sss.pgh.pa.us writes:

 Alvaro Herrera alvhe...@alvh.no-ip.org writes:
 Grzegorz Jaśkiewicz wrote:
 looks like it really has to be defined with char in double quotes. I
 thought just char is enough...

 They're different types.

 You know, maybe we should stop holding our noses and do something about
 this old gotcha.  That type's not going away anytime soon, but could we
 rename it to char1 or something like that? 

int1?


-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com
  Ask me about EnterpriseDB's Slony Replication support!

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-04 Thread Merlin Moncure
On Tue, Feb 3, 2009 at 6:16 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 Merlin Moncure mmonc...@gmail.com writes:
 On Tue, Feb 3, 2009 at 4:28 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 You know, maybe we should stop holding our noses and do something about
 this old gotcha.  That type's not going away anytime soon, but could we
 rename it to char1 or something like that?  (With some sort of backward
 compatibility hack, like a domain named char.)

 domains are out, unless arrays of domains are addressed first.

 [ raised eyebrow... ]  You've got apps that depend on array of char?

yes.  For example. I wrote a ISAM emulation wrapper for libpq a few
years back that supported some cobol applicaitons.  char(1) fields are
common cobol (and were mapped to char for performance), as are
arrays of records.  since at the time there was no support for arrays
of composites or domains, I had to use parallel arrays of POD types
when mapping these types of records to PostgreSQL. This would now
break.

Anyways, why prefer domain to type alias (char1 : char :: bigint :
int8)?  Main advantage of domains is being able to add user level
constraints, which is kinda weird for system provided type.

merlin

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Grzegorz Jaśkiewicz
  char  c = PG_GETARG_CHAR(1);


for whatever reason, taht doesn't return the real char that was passed in.


-- 
GJ

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Alvaro Herrera
Grzegorz Jaśkiewicz wrote:
   char  c = PG_GETARG_CHAR(1);
 
 for whatever reason, taht doesn't return the real char that was passed in.

Yeah ... try DatumGetBpCharP instead.  PG_GETARG_CHAR is for type char
with quotes, which is a completely different thing.

-- 
Alvaro Herrera   Valdivia, Chile   ICBM: S 39º 49' 18.1, W 73º 13' 56.4
The problem with the facetime model is not just that it's demoralizing, but
that the people pretending to work interrupt the ones actually working.
   (Paul Graham)

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Tom Lane
Alvaro Herrera alvhe...@alvh.no-ip.org writes:
 Grzegorz Jaśkiewicz wrote:
 for whatever reason, taht doesn't return the real char that was passed in.

 Yeah ... try DatumGetBpCharP instead.  PG_GETARG_CHAR is for type char
 with quotes, which is a completely different thing.

Or maybe the C code does just what he wants, and the problem is that he
needs to declare the function correctly at the SQL level (ie, with
second argument char not char(1)).

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Tom Lane
Alvaro Herrera alvhe...@alvh.no-ip.org writes:
 Grzegorz Jaśkiewicz wrote:
 looks like it really has to be defined with char in double quotes. I
 thought just char is enough...

 They're different types.

You know, maybe we should stop holding our noses and do something about
this old gotcha.  That type's not going away anytime soon, but could we
rename it to char1 or something like that?  (With some sort of backward
compatibility hack, like a domain named char.)

On the other hand, that might be more trouble than it's worth.  Even
with a domain alias, there'd be a nontrivial chance of breaking apps
that look at the char columns of the system catalogs.

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Alvaro Herrera
Grzegorz Jaśkiewicz wrote:
 looks like it really has to be defined with char in double quotes. I
 thought just char is enough...

They're different types.

-- 
Alvaro Herrera http://www.flickr.com/photos/alvherre/
Crear es tan difícil como ser libre (Elsa Triolet)

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Merlin Moncure
On Tue, Feb 3, 2009 at 4:28 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 Alvaro Herrera alvhe...@alvh.no-ip.org writes:
 Grzegorz Jaśkiewicz wrote:
 looks like it really has to be defined with char in double quotes. I
 thought just char is enough...

 They're different types.

 You know, maybe we should stop holding our noses and do something about
 this old gotcha.  That type's not going away anytime soon, but could we
 rename it to char1 or something like that?  (With some sort of backward
 compatibility hack, like a domain named char.)

 On the other hand, that might be more trouble than it's worth.  Even
 with a domain alias, there'd be a nontrivial chance of breaking apps
 that look at the char columns of the system catalogs.

domains are out, unless arrays of domains are addressed first.

merlin

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Grzegorz Jaśkiewicz
it's defined:

create or replace function filter_text(text, char) returns text as
'test_proc.so' language 'c';


which leads me to another question.
It seems that I have to leave psql and comeback, for new version to be
loaded. (that's on 8.4 tho, I don't have 8.3 at home).
And also that 'replace' bit doesn't seem to actually refresh it either.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Grzegorz Jaśkiewicz
looks like it really has to be defined with char in double quotes. I
thought just char is enough...

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Grzegorz Jaśkiewicz
On Tue, Feb 3, 2009 at 9:28 PM, Tom Lane t...@sss.pgh.pa.us wrote:

 On the other hand, that might be more trouble than it's worth.  Even
 with a domain alias, there'd be a nontrivial chance of breaking apps
 that look at the char columns of the system catalogs.


I have to apologize, it is clearly written in quotes in docs - but
obviously I couldn't believe that would make any difference.



-- 
GJ

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] C function question

2009-02-03 Thread Tom Lane
Merlin Moncure mmonc...@gmail.com writes:
 On Tue, Feb 3, 2009 at 4:28 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 You know, maybe we should stop holding our noses and do something about
 this old gotcha.  That type's not going away anytime soon, but could we
 rename it to char1 or something like that?  (With some sort of backward
 compatibility hack, like a domain named char.)

 domains are out, unless arrays of domains are addressed first.

[ raised eyebrow... ]  You've got apps that depend on array of char?

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] C function question

2009-02-03 Thread Grzegorz Jaśkiewicz
Hey folks
I am trying to write simple function, that would filter out a char
from text/string. It's being a while since I last time wrote c
function for postgresql (8.1), and few things are gone in API there.
Can someone tell me what's wrong with that function please ?

#include postgres.h
#include string.h
#include fmgr.h
#include utils/builtins.h
#include libpq/pqformat.h


PG_FUNCTION_INFO_V1(filter_text);

PG_MODULE_MAGIC;

// filter_text(text, char);

Datum
filter_text(PG_FUNCTION_ARGS)
{
  text  *arg1 = PG_GETARG_TEXT_P(0);
  char  c = PG_GETARG_CHAR(1);

  int i, j;

  text *new_text;

  if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
PG_RETURN_NULL();

  new_text = (text *) palloc(VARSIZE(arg1)+VARHDRSZ);
  SET_VARSIZE(new_text, VARSIZE(arg1)+VARHDRSZ);

  for(i=0, j=0; i!=VARSIZE(arg1)-VARHDRSZ; i++)
  {
if ( VARDATA(arg1)[i] != c )
{
  VARDATA(new_text)[j++] = VARDATA(arg1)[i];
}
  }

  VARDATA(new_text)[j++] = '\0';

  SET_VARSIZE(new_text, j+VARHDRSZ);

  PG_RETURN_TEXT_P(new_text);
}

-- 
GJ

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general