Re: lo_creat SQL command

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: lo_creat SQL command
Date: 2005-04-22 00:17:53
Message-ID: 20050422001753.GA44039@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, Apr 21, 2005 at 11:18:57PM +0300, Volkan YAZICI wrote:
>
> I'd be so apprecited if somebody could help me to figure out the
> meaning of required parameter for lo_creat() function. In libpq, you
> just pass connection and mode params to lo_creat() function. But when
> we look at the server-side lo_create() function:
>
> Schema: pg_catalog
> Name: lo_creat
> Result data type: oid
> Argument data types: integer
>
> documentation/lo-funcs.html just uses -1 to create a new empty lo. I'm
> cosidering parameter as the database connection to create the large
> object. So -1 indicates the current connection. If this is right, how
> can I pass another connection to lo_creat() SQL function?

The source code for the backend lo_creat() calls the argument "mode",
which would correspond to the second argument of the client-side
(libpq) lo_creat(). The server-side lo_creat() passes "mode" to
inv_create(), which calls the argument "flags". That function
contains the following code:

if (flags & INV_WRITE)
retval->flags = IFS_WRLOCK | IFS_RDLOCK;
else if (flags & INV_READ)
retval->flags = IFS_RDLOCK;
else
elog(ERROR, "invalid flags: %d", flags);

> Also it'd perfect if somebody can also point me the file in postgresql
> source code which defines these lo functions.

Various source code tools make it easy to browse code and find
functions, but even without such tools you can use find and grep:

% find src -name '*.c' | xargs grep '^lo_creat'
src/backend/libpq/be-fsstubs.c:lo_creat(PG_FUNCTION_ARGS)
src/interfaces/libpq/fe-lobj.c:lo_creat(PGconn *conn, int mode)

or

% grep '^lo_creat' `find src -name '*.c'`
src/backend/libpq/be-fsstubs.c:lo_creat(PG_FUNCTION_ARGS)
src/interfaces/libpq/fe-lobj.c:lo_creat(PGconn *conn, int mode)

(Be careful to distinguish between single quotes and backticks in
the above commands.)

Functions in the source code don't always have the same name as in
SQL, so before doing a search like the above you might need to query
the system catalogs. For example, if you wanted to find the source
code for the abs() function, you could execute this query:

SELECT p.proname, oidvectortypes(p.proargtypes) AS argtypes,
g.lanname, p.prosrc
FROM pg_proc AS p JOIN pg_language AS g ON g.oid = p.prolang
WHERE proname = 'abs';
proname | argtypes | lanname | prosrc
---------+------------------+----------+-------------
abs | numeric | internal | numeric_abs
abs | double precision | internal | float8abs
abs | real | internal | float4abs
abs | integer | internal | int4abs
abs | smallint | internal | int2abs
abs | bigint | internal | int8abs
(6 rows)

You'd then search the source code for numeric_abs, float8abs, etc.
Note that the meaning of prosrc varies depending on the language --
in this case the language is "internal", so prosrc refers to a
function in the PostgreSQL source code.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Pradeepkumar, Pyatalo (IE10) 2005-04-22 08:28:57 Re: Disk full problem
Previous Message Michael Fuhr 2005-04-21 23:42:24 Re: Granting permission on a sequence to a group