[SQL] pg_attribute.attlen -1 for varchar e pbchar fields
Hi listers, I'm facing a problem getting information from meta tables. The command: SELECT attname, atttypid, attlen FROM pg_attribute where atttypid IN(1042, 1043) The attlen column always returns -1 for bpchar and varchar columns. the postgre version is 8.0.1. When I look the tables in pgAdmin the column lengths are correct. Where can I find the correct column lengths?? Alessandro - Liga One Sistemas [EMAIL PROTECTED] ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [SQL] getting back autonumber ... Another MsSQL Comparation Question
Hi Listers, I need to know the number of affected (Inserted, deleted, updated) rows by a Query. In MsSQL I use SELECT @@ROWCOUNT, similar to SELECT @@IDENTITY. Is there any @@RowCount similar statement in PostGres?? Alessandro - Liga One Sistemas [EMAIL PROTECTED] - Original Message - From: "Alvaro Herrera" <[EMAIL PROTECTED]> To: "mail TechEvolution" <[EMAIL PROTECTED]> Cc: Sent: Thursday, July 07, 2005 3:03 PM Subject: Re: [SQL] getting back autonumber just inserted > On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote: > > hello > > > > i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 > > (windowsinstaller) on a xp prof platform > > > > i would like to get back the autonumber from the last record inserted, > > for other SQL db (m$ sql db ...) i could use: > > SELECT @@ IDENTITY > > > > can someone help me by informing me what the SQL syntax is to be used > > with PostGreSQL db and get the same result, the last autonumber inserted? > > You use the currval() function, using the name of the involved sequence > as parameter. There is a pg_get_serial_sequence() function, to which > you give the table name and column name, and it will give you the > sequence name. > > -- > Alvaro Herrera () > Oh, oh, las chicas galacianas, lo harán por las perlas, > ¡Y las de Arrakis por el agua! Pero si buscas damas > Que se consuman como llamas, ¡Prueba una hija de Caladan! (Gurney Halleck) > > ---(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 > ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [SQL] getting back autonumber just inserted
I don't know how to create a Global Variable in Postgres, but the idea is
very simple:
1. Encapsulate the NextVal function in MyNextVal
2. Set to Global variable with NextVal of the desired sequence
3. Inspect to value of the global variable (exactally as it's done in MsSQL)
When Creating a Table:
CREATE TABLE tabTest(
codTest Int Not Null PRIMARY KEY DEFAULT(NextVal("seq_test"),
... # Field List
)
Try this:
CREATE TABLE tabTest(
codTest Int Not Null PRIMARY KEY DEFAULT(MyNextVal("seq_test"),
... # Field List
)
this is not the correct sintax, just an algoritm
CREATE FUNCTION MyNextVal(varchar) RETURNS INT AS
$$ SELECT GlobalVar = NextVal($1)
RETURN GlobalVar
$$
Alessandro - Liga One Sistemas
[EMAIL PROTECTED]
- Original Message -
From: "Alvaro Herrera" <[EMAIL PROTECTED]>
To: "mail TechEvolution" <[EMAIL PROTECTED]>
Cc:
Sent: Thursday, July 07, 2005 3:03 PM
Subject: Re: [SQL] getting back autonumber just inserted
> On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote:
> > hello
> >
> > i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0
> > (windowsinstaller) on a xp prof platform
> >
> > i would like to get back the autonumber from the last record inserted,
> > for other SQL db (m$ sql db ...) i could use:
> > SELECT @@ IDENTITY
> >
> > can someone help me by informing me what the SQL syntax is to be used
> > with PostGreSQL db and get the same result, the last autonumber
inserted?
>
> You use the currval() function, using the name of the involved sequence
> as parameter. There is a pg_get_serial_sequence() function, to which
> you give the table name and column name, and it will give you the
> sequence name.
>
> --
> Alvaro Herrera ()
> Oh, oh, las chicas galacianas, lo harán por las perlas,
> ¡Y las de Arrakis por el agua! Pero si buscas damas
> Que se consuman como llamas, ¡Prueba una hija de Caladan! (Gurney Halleck)
>
> ---(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
>
---(end of broadcast)---
TIP 4: Have you searched our list archives?
http://archives.postgresql.org
