Обсуждение: Primary Key

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

Primary Key

От
raghu nidagal
Дата:
Hi,
I want to know how i can find out if a particular field in a
resultset is a primary key. Also is the OID automatically retrieved
as part of every select query?
thanks
raghu



--------------------------------------------------------------------------
Global Internet phone calls, voicemail, fax, e-mail and instant messaging.
Sign-up today at http://www.hotvoice.com

Re: Primary Key

От
Дата:
No, the OID, as every system field, isn't retrieved automatcally in a ResulSet, for example with a query such as:
"SELECT* FROM Addr;". You must specify the system fields that you want. For example "SELECT oid,* FROM Addr;". 

I have a question. Is it possible, after a table creation, to declare a field as a PRIMARY KEY? In particular I want to
declareexplicity the system field oid as a PRIMARY KEY. 

Many thanks!

Riccardo


__________________________________________


Fai i tuoi acquisti su www.kwshopping.it


getColumns()

От
Auri Mason
Дата:
Hi list,

in my applications I use getColumns() method to retrieve the size of some
fileds to avoid the exceed of the field size during an insert.
This procedure works fine with oracle, DB2 and MSsql JDBC but seems it
doesn't work (return a null) with the postgresql JDBC driver (feb 9 2002
release).
Anyone of you has some note/fix/workaround about this?

p.s. I use % as schema

TIA, Auri



Re: getColumns()

От
Dave Cramer
Дата:
Auri,

AFAIK this works, can you give me specifics?

ie db version, columns, code sample, etc.

Dave
On Wed, 2002-04-03 at 11:22, Auri Mason wrote:
> Hi list,
>
> in my applications I use getColumns() method to retrieve the size of some
> fileds to avoid the exceed of the field size during an insert.
> This procedure works fine with oracle, DB2 and MSsql JDBC but seems it
> doesn't work (return a null) with the postgresql JDBC driver (feb 9 2002
> release).
> Anyone of you has some note/fix/workaround about this?
>
> p.s. I use % as schema
>
> TIA, Auri
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>



Re: getColumns()

От
Auri Mason
Дата:
Hi Dave,

As far as you known it works? Sounds good!

BTW, I'm using Postgresql 7.1.3 and the 'incriminated' code is:

####### Code example ########
...
        private DatabaseMetaData dma;
        private Connection dbCon;
...
        /**
                the schema is set to "%"
        */
        public void setSchema(String schema) {
                this.schema = schema;
        }
        /**
        * This function is used to get the current used schema name to
perform table and fields checks in the right schema.
        private String getSchema() {
                return schema;
        }

        private String getCatalog() throws SQLException {
                String catalog = dbCon.getCatalog();
                if (catalog != null && catalog.length() == 0) {
                        catalog = null;
                }
                return catalog;
        }
...
  public int getFieldSize(String tableName, String fieldName, String
schema) throws BDEException {
                int ret = -1;
                try {
//->>>>>>>>>>>>the following returns no rows!
                        ResultSet rs = dma.getColumns(getCatalog(),
getSchema(), tableName.toUpperCase(),
fieldName.toUpperCase());

                        rs.next();
//So this throws an exception...
                        ret = rs.getInt("COLUMN_SIZE");
                } catch (Exception e) {
                        trace.fail(e);
                }
//...and this returns null
                return ret;
        }
############# EO Code sample ############

TIA, Auri


On 3 Apr 2002, Dave Cramer wrote:

> Auri,
>
> AFAIK this works, can you give me specifics?
>
> ie db version, columns, code sample, etc.
>
> Dave


Re: getColumns()

От
"Jose Javier Gutierrez"
Дата:
Hi ,
    I have any problems wiht postgres. My error i s the follow :

"ERROR:  UNIQUE constraint matching given keys for referenced table
"content_version" not found"

What 's the problem?.





Re: getColumns()

От
Dave Cramer
Дата:
Jose,

It looks like your database is missing some information. Try dumping the
table schema to see what the constraint is trying to do. Did you rename
a column?

Dave
On Thu, 2002-04-04 at 03:42, Jose Javier Gutierrez wrote:
>
> Hi ,
>     I have any problems wiht postgres. My error i s the follow :
>
> "ERROR:  UNIQUE constraint matching given keys for referenced table
> "content_version" not found"
>
> What 's the problem?.
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>




Re: getColumns() - workaround

От
Auri Mason
Дата:
I've find the workaround for postreSQL

//->>>>>>>>>>>>the following returns no rows!
ResultSet rs = dma.getColumns(getCatalog(), getSchema(), tableName.toUpperCase(), fieldName.toUpperCase());

//->>>> the following WORKS FINE!
ResultSet rs = dma.getColumns("", "",tableName.toLowerCase(), fieldName.toLowerCase());

BTW, it doesn't work if tablename is a view :(

--
Auri



On 3 Apr 2002, Dave Cramer wrote:

> Auri,
>
> AFAIK this works, can you give me specifics?
>
> ie db version, columns, code sample, etc.
>
> Dave
> On Wed, 2002-04-03 at 11:22, Auri Mason wrote:
> > Hi list,
> >
> > in my applications I use getColumns() method to retrieve the size of some
> > fileds to avoid the exceed of the field size during an insert.
> > This procedure works fine with oracle, DB2 and MSsql JDBC but seems it
> > doesn't work (return a null) with the postgresql JDBC driver (feb 9 2002
> > release).
> > Anyone of you has some note/fix/workaround about this?
> >
> > p.s. I use % as schema


Re: getColumns() - workaround

От
Auri Mason
Дата:
again me.. :)

works fine also with a view! ^_____^

On Thu, 4 Apr 2002, Auri Mason wrote:

> I've find the workaround for postreSQL
>
> //->>>>>>>>>>>>the following returns no rows!
> ResultSet rs = dma.getColumns(getCatalog(), getSchema(), tableName.toUpperCase(), fieldName.toUpperCase());
>
> //->>>> the following WORKS FINE!
> ResultSet rs = dma.getColumns("", "",tableName.toLowerCase(), fieldName.toLowerCase());
>
> BTW, it doesn't work if tablename is a view :(
>
> --
> Auri


Re: getColumns() - workaround

От
Dave Cramer
Дата:
Auri,

Yes, if you go into psql and look at your tables you will find that they
are all lower case, regardless of how you created them.

Dave
On Thu, 2002-04-04 at 08:44, Auri Mason wrote:
> I've find the workaround for postreSQL
>
> //->>>>>>>>>>>>the following returns no rows!
> ResultSet rs = dma.getColumns(getCatalog(), getSchema(), tableName.toUpperCase(), fieldName.toUpperCase());
>
> //->>>> the following WORKS FINE!
> ResultSet rs = dma.getColumns("", "",tableName.toLowerCase(), fieldName.toLowerCase());
>
> BTW, it doesn't work if tablename is a view :(
>
> --
> Auri
>
>
>
> On 3 Apr 2002, Dave Cramer wrote:
>
> > Auri,
> >
> > AFAIK this works, can you give me specifics?
> >
> > ie db version, columns, code sample, etc.
> >
> > Dave
> > On Wed, 2002-04-03 at 11:22, Auri Mason wrote:
> > > Hi list,
> > >
> > > in my applications I use getColumns() method to retrieve the size of some
> > > fileds to avoid the exceed of the field size during an insert.
> > > This procedure works fine with oracle, DB2 and MSsql JDBC but seems it
> > > doesn't work (return a null) with the postgresql JDBC driver (feb 9 2002
> > > release).
> > > Anyone of you has some note/fix/workaround about this?
> > >
> > > p.s. I use % as schema
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>