Обсуждение: how to obtain column info

Поиск
Список
Период
Сортировка

how to obtain column info

От
"Ken J. Wright"
Дата:
With libpq, how do you obtain column info (like type) for a table *before*
returning a result set? For instance, knowing the column type before
constructing an insert statement. A date will need quotes, a number won't,
a string will, etc.

Thanks,

Ken

Re: [INTERFACES] how to obtain column info

От
"Cary B. O'Brien"
Дата:
> With libpq, how do you obtain column info (like type) for a table *before*
> returning a result set? For instance, knowing the column type before
> constructing an insert statement. A date will need quotes, a number won't,
> a string will, etc.
>

I usually do a 'select * from table_x where oid < 0' or something like
that to get an empty result set.  This might be a stupid thing to do on
a big table, thought.  You might want to select a column with an index.
Anyone have a better idea?

Actually, you should be able to get the information out of the pg_ tables.

-- cary

Re: [INTERFACES] how to obtain column info

От
Brett McCormick
Дата:
If you just want to know whether or not to quote it, just see if it
has any non-numerical characters.  If so, quote it, otherwise, leave
it alone.  Seems like their would be a loss in performace if you
checked the types instead of just quoting everything (which works
fine).

On Tue, 10 November 1998, at 16:38:02, Ken J. Wright wrote:

> With libpq, how do you obtain column info (like type) for a table *before*
> returning a result set? For instance, knowing the column type before
> constructing an insert statement. A date will need quotes, a number won't,
> a string will, etc.
>
> Thanks,
>
> Ken
>

Re: [INTERFACES] how to obtain column info

От
Herouth Maoz
Дата:
At 3:34 +0200 on 11/11/98, Cary B. O'Brien wrote:


> I usually do a 'select * from table_x where oid < 0' or something like
> that to get an empty result set.

I always maintain that it's more elegant to write

SELECT *
FROM table_x
WHERE 'false'::bool;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma