Re: [HACKERS] PQftype implementation

2010-03-18 Thread Pavel Golub
Hello, Tom.

Yes, you are absolutely right. My bad!

Sorry guys! :)

You wrote:

TL Pavel Golub pa...@microolap.com writes:
 Here I created user-defined type my_varchar for internal tests. But
 PQftype returns 1043 (varchar oid) for the info column.

TL Really?  I tried it and got 172069, which is about right for where the
TL OID counter is in my database.  I think you messed up your test.

TL res = PQexec(conn, select * from my_varchar_test);
TL if (PQresultStatus(res) != PGRES_TUPLES_OK)
TL {
TL fprintf(stderr, SELECT failed: %s, PQerrorMessage(conn));
TL PQclear(res);
TL exit_nicely(conn);
TL }

TL nFields = PQnfields(res);
TL for (i = 0; i  nFields; i++)
TL printf(%-15s %d\n, PQfname(res, i), PQftype(res, i));

TL regards, tom lane



-- 
With best wishes,
 Pavel  mailto:pa...@gf.microolap.com


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


[HACKERS] PQftype implementation

2010-03-17 Thread Pavel Golub
Hello, Pgsql-hackers.

The script:

CREATE TYPE my_varchar;


CREATE OR REPLACE FUNCTION my_varcharout(my_varchar)
  RETURNS cstring AS
'varcharout'
  LANGUAGE 'internal' IMMUTABLE STRICT
  COST 1;

CREATE OR REPLACE FUNCTION my_varcharin(cstring, oid, integer)
  RETURNS my_varchar AS
'varcharin'
  LANGUAGE 'internal' IMMUTABLE STRICT
  COST 1;
  
CREATE TYPE my_varchar
   (INPUT=my_varcharin, OUTPUT=my_varcharout, DEFAULT='',
   INTERNALLENGTH=-1, ALIGNMENT=int4, STORAGE=EXTENDED,
   TYPMOD_IN=varchartypmodin, TYPMOD_OUT=varchartypmodout);

CREATE TABLE my_varchar_test(
id serial primary key,
info my_varchar(100)
)

Here I created user-defined type my_varchar for internal tests. But
PQftype returns 1043 (varchar oid) for the info column.

I'm a little bit confused of such behaviour. What am I missing?
Ans where in the sources can I find the way server fills
res-attDescs[field_num].typid?

Thanks in advance.

-- 
With best wishes,
 Pavel  mailto:pa...@gf.microolap.com


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


Re: [HACKERS] PQftype implementation

2010-03-17 Thread Tom Lane
Pavel Golub pa...@microolap.com writes:
 Here I created user-defined type my_varchar for internal tests. But
 PQftype returns 1043 (varchar oid) for the info column.

Really?  I tried it and got 172069, which is about right for where the
OID counter is in my database.  I think you messed up your test.

res = PQexec(conn, select * from my_varchar_test);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, SELECT failed: %s, PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}

nFields = PQnfields(res);
for (i = 0; i  nFields; i++)
printf(%-15s %d\n, PQfname(res, i), PQftype(res, i));

regards, tom lane

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


Re: [HACKERS] PQftype()

2001-04-30 Thread Magnus Naeslund\(f\)

From: Tom Lane [EMAIL PROTECTED]
 Magnus Naeslund\(f\) [EMAIL PROTECTED] writes:
  Where do get a listing of what PQftype() can return to me?
 
 select oid, typname from pg_type
 
 regards, tom lane

Does these change often?
Or could i do like the ODBC driver, autogenerate a .h out of that table.

Magnus

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Programmer/Networker [|] Magnus Naeslund
 PGP Key: http://www.genline.nu/mag_pgp.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [HACKERS] PQftype()

2001-04-30 Thread Magnus Naeslund\(f\)

From: Tom Lane [EMAIL PROTECTED]
[snip]

 The system type OIDs are stable.  User-defined types would probably have
 a new OID after a dump and reload.

  Or could i do like the ODBC driver, autogenerate a .h out of that table.

 I would not recommend relying on compiled-in OID knowledge for any types
 other than the system-defined datatypes.  If you expect to have to deal
 with user-defined types, it's best to cache the results of pg_type
 lookups at the client end.  You need not worry about OIDs changing
 during a single client connection.

 regards, tom lane


Ok, then i can use static thing for my application (for now atleast).
Thanks..

Magnus


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])



Re: [HACKERS] PQftype()

2001-04-30 Thread Tom Lane

Magnus Naeslund\(f\) [EMAIL PROTECTED] writes:
 Where do get a listing of what PQftype() can return to me?
 
 select oid, typname from pg_type

 Does these change often?

The system type OIDs are stable.  User-defined types would probably have
a new OID after a dump and reload.

 Or could i do like the ODBC driver, autogenerate a .h out of that table.

I would not recommend relying on compiled-in OID knowledge for any types
other than the system-defined datatypes.  If you expect to have to deal
with user-defined types, it's best to cache the results of pg_type
lookups at the client end.  You need not worry about OIDs changing
during a single client connection.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])



Re: [HACKERS] PQftype()

2001-04-29 Thread Tom Lane

Magnus Naeslund\(f\) [EMAIL PROTECTED] writes:
 Where do get a listing of what PQftype() can return to me?

select oid, typname from pg_type

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly