[SQL] SELECT with WHERE clause by column number

2006-12-18 Thread Carlos Santos
Hi!

I need to make a query like this:

SELECT id FROM myTable WHERE column-number = 'value';
(PS: The id column is the primary key of myTable).

That is a select using column number in the WHERE clause what don't exists in 
SQL.

I need this because there's a situation in my program where I don't have the 
column name.
I've solved that querying Postgresql the name of the column with that number, 
and then creating  the SELECT query.
But this solution is slow... two database calls...

Can I do this with a single query or in a faster way  through SQL, an internal 
function or through a Procedural Language?

Thanks 
 
 Carlos Henrique Iazzetti Santos 

Compels Informática 
 Santa Rita do Sapucaí - MG
BRAZIL
www.compels.net













___ 
Você quer respostas para suas perguntas? Ou você sabe muito e quer compartilhar 
seu conhecimento? Experimente o Yahoo! Respostas !
http://br.answers.yahoo.com/

Res: [SQL] SELECT with WHERE clause by column number

2006-12-18 Thread Carlos Santos
All my columns have the same data type: text.
So it's much easier.
 
Carlos Henrique Iazzetti Santos 
Compels Informática 
 Santa Rita do Sapucaí - MG
www.compels.net


- Mensagem original 
De: Richard Huxton 
Para: Carlos Santos <[EMAIL PROTECTED]>
Cc: Lista PostgreSQL SQL 
Enviadas: Segunda-feira, 18 de Dezembro de 2006 15:25:27
Assunto: Re: [SQL] SELECT with WHERE clause by column number

Carlos Santos wrote:
> SELECT id FROM myTable WHERE column-number = 'value';
> (PS: The id column is the primary key of myTable).
> 
> That is a select using column number in the WHERE clause what don't exists in 
> SQL.
> 
> I need this because there's a situation in my program where I don't have the 
> column name.
> I've solved that querying Postgresql the name of the column with that number, 
> and then creating  the SELECT query.
> But this solution is slow... two database calls...

If you don't know what the column is, how do you know what you are 
testing against? Or what type it is, for that matter?

Anyway, just have build a list of column-name,column-type pairs for 
relevant tables at application start-up, or store it in a configuration 
file. Unless you're building/changing tables all the time, that should work.

I'm curious as to what type of application can usefuly query a database 
without knowing what structure it has.

-- 
   Richard Huxton
   Archonet Ltd

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org








___ 
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale 
o discador agora! 
http://br.acesso.yahoo.com

[SQL] Query a select that returns all the fields of an specific value of primary key without knownig the name of the single column's primary key?

2006-12-19 Thread Carlos Santos
Hi!
I need to query a select that returns all the fields of an specific primary 
key, but I don't have the  single column's name that is constrained as primary 
key.
How can I do that?
Something like:
SELECT * FROM myTable WHERE myTable.pkey = 'foo';

Thanks
 
Carlos Henrique Iazzetti Santos 
Compels Informática 
 Santa Rita do Sapucaí - MG
www.compels.net






___ 
O Yahoo! está de cara nova. Venha conferir! 
http://br.yahoo.com

[SQL] LOCK command inside a TRANSACTION

2007-04-03 Thread Carlos Santos
Hi!
I need Postgresql somehow does this for me:
- if an user query a select on a table, the rows of the table in the result of 
this select can not be updated or deleted by another user until this one 
update, delete or discard the changes on those rows.

I've found something about the LOCK command inside a TRANSACTION but I didn't 
see how I could do that yet.

Does anybody have any ideas?
 
Carlos Henrique Iazzetti Santos 
Compels Informática 
 Santa Rita do Sapucaí - MG
Brazil
www.compels.net




__
Fale com seus amigos  de graça com o novo Yahoo! Messenger 
http://br.messenger.yahoo.com/ 

[SQL] How can I know if a row is Locked?

2007-04-13 Thread Carlos Santos
How can I know if a row is locked by another transaction.
I have in a transaction like that:

BEGIN;
SELECT * FROM compels.teste WHERE id = '1' FOR UPDATE;

PS1: where id is the primary key.
PS2: The COMMIT command is done after a long time.

In this case the row with the primary-key equals to '1' will be locked to other 
transactions until the COMMIT command be executed.
So, how can I detect if this row is locked?

Tks
 
Carlos Henrique Iazzetti Santos 
Compels Informática 
 Santa Rita do Sapucaí - MG
www.compels.net




__
Fale com seus amigos  de graça com o novo Yahoo! Messenger 
http://br.messenger.yahoo.com/