PGresult#type (and other postgres questions)

G

Gavin Kistner

I'm putting RDoc documents into postgres.c, and I have a few questions
about what various methods do.


PGresult#type( fieldIndex )
What does the number that is returned correspond to?
(Looks like integer/serial is 23, varchar(50) is 1043, smallint is 21
.... where is there a lookup of constants for these values?)



PGconn.escape()
PGconn.escape_bytea( ... )
What do these two class methods do? (They're not documented in the
supplied documentation. Neither is PGconn.quote either, but I figured
that one out.)



PGconn#insert_table( table, values )
What is 'table'? The supplied documentation merely says
Inserts contents of the array into the table.
My guess (from playing around) is that 'table' is a String with the name
of the table, and 'values' must be an Array of tuples (array of arrays).
Is this correct?

Also, is there any way to use this method to insert values into a table
where one column is of type 'serial'? You can explicitly shove an
integer in, but doing so does not cause the serial value to
auto-increment...a future call to insert a value in the table which
doesn't specify a value for the serial column may choose an existing
value, and error.


PGconn#notifies()
What does this method do? (Not in the supplied documentation.)


PGconn#status()
What does this method do? (Not in the supplied documentation.)


PGresult#cmdtuples()
What does this method do? (Not in the supplied documentation.)
res = conn.exec('select * from t_lists;')
puts res.result.length => 5
puts res.cmdtuples => 0


(More to come as a followup, likely :)
 
M

Martin Hart

I'm putting RDoc documents into postgres.c, and I have a few questions
about what various methods do.

PGconn.escape()
PGconn.escape_bytea( ... )
What do these two class methods do? (They're not documented in the
supplied documentation. Neither is PGconn.quote either, but I figured
that one out.)

Escape the supplied string so that it is valid SQL I believe - e.g. replace '
with either '' or \' (can't remember which)
PGconn#notifies()
What does this method do? (Not in the supplied documentation.)

This supplies information about the backend notifies waiting to be processed
(see NOTIFY and LISTEN in postgres documentation)


Sorry for being terse and not answering everything - if nobody else has
replied when I finish for the day, I'll send through a more detailed response
:)

NOTE - the last time I used ruby-postgres (just after pgsql 7.4 release) it
was broken with Postgresql 7.4 in that the listen/notify stuff did not work
properly. It may have been patched since then - I'll dig through my notes
from the time.

Cheers,
Martin

--
Martin Hart
Arnclan Limited
53 Union Street
Dunstable, Beds
LU6 1EX
http://www.arnclanit.com
 
T

ts

G> PGresult#type( fieldIndex )
G> What does the number that is returned correspond to?

OID

G> (Looks like integer/serial is 23, varchar(50) is 1043, smallint is 21
G> .... where is there a lookup of constants for these values?)

select oid, typname from pg_type;

G> PGconn.escape()

Take a String and escape it

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-STRING

G> PGconn.escape_bytea( ... )

same than previous but with binary strings

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-BYTEA



G> PGconn#insert_table( table, values )
G> What is 'table'? The supplied documentation merely says
G> Inserts contents of the array into the table.
G> My guess (from playing around) is that 'table' is a String with the name
G> of the table, and 'values' must be an Array of tuples (array of arrays).
G> Is this correct?

yes

G> PGconn#status()
G> What does this method do? (Not in the supplied documentation.)

Returns the result status of the command (PQresultStatus)

http://www.postgresql.org/docs/7.4/static/libpq-exec.html

G> PGresult#cmdtuples()
G> What does this method do? (Not in the supplied documentation.)

Returns the number of rows affected by the SQL command. (PQcmdTuples)

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-NONSELECT

Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top