I have a DB2 database, where few of the tablenames are starting with '/'.
eg: /dev/r32
How can I query on the above table
I have tried with the following approaches
select * from schemaname./dev/r32
select * from schemaname.'/dev/r32'
select * from schemaname."/dev/r32"
But I am getting the following error:
An error occurred when executing the SQL command:
select * from schemaname."/dev/r32"
[SQL0204] /dev/r32 in schemaname type *FILE not found. [SQL State=42704, DB Errorcode=-204]
describe schemaname."/dev/r32" works.
Any help would be appreciated
The table names are changed and issue is resolved.
Related
I'm trying to run pg_dump and it's failing due to a orphaned sequence.
pg_dump -U db --format=custom --compress=0 db
pg_dump: error: query to get data of sequence "non_existing_table_id_seq" returned 0 rows (expected 1)
https://wiki.postgresql.org/wiki/Fixing_Sequences
The above wiki page has some snippets which can be used to fix this issue, the last snippit does work to display the orphaned snippets.
select ns.nspname as schema_name, seq.relname as seq_name
from pg_class as seq
join pg_namespace ns on (seq.relnamespace=ns.oid)
where seq.relkind = 'S'
and not exists (select * from pg_depend where objid=seq.oid and deptype='a')
order by seq.relname;
schema_name | seq_name
-------------+--------------------------------
public | non_existing_table_id_seq
public | another_non_existing_table_id_seq
(2 rows)
The command which should fix this issue doesn't run because column d.adsrc does not exist
It seems to have been removed from postgres-12.
https://stackoverflow.com/a/58798028/1891184 says I can replace d.adsrc with pg_get_expr(d.adbin, d.adrelid). and that runs, however the issue still remains.
Other than this, the database is working fine.
How can I either fix or remove the offending sequences in order to let pg_dump work?
I am working with a script made for SQLite but I need to adapt it to a PostgreSQL database and this line is always returning an error:
PRAGMA table_info(table)
How can I get an equivalent result on postgres >
Found it !
SELECT *
FROM information_schema.columns
WHERE table_name = 'table_name'
I'm updating a Linux server with a new version of PostgreSql and I have an Error Message in phpPgAdmin when I browse a table.
The Ubuntu 18.04.3 LTS server running Apache 2.4.41, PHP 7.3.11 and when I update to PostgreSQL 12.0 and phpPgAdmin 7.12.0 the error occurs. With PostgreSQL 11.5 and phpPgAdmin 5.6 I didn't have this problem.
I expect to visualize the data stored in the table using phpPgAdmin, but the actual output is:
SQL error:
ERROR: column «relhasoids» does not exist
LINE 1: SELECT relhasoids FROM pg_catalog.pg_class WHERE relname='pr...
In statement:
SELECT relhasoids FROM pg_catalog.pg_class WHERE relname='product'
AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='public')
Editing the file /usr/share/phppgadmin/classes/database/Postgres.php and comment line 1045 to line 1054 the error disappears:
function hasObjectID($table) {
$c_schema = $this->_schema;
$this->clean($c_schema);
$this->clean($table);
/*
$sql = "SELECT relhasoids FROM pg_catalog.pg_class WHERE relname='{$table}'
AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$c_schema}')";
$rs = $this->selectSet($sql);
if ($rs->recordCount() != 1) return null;
else {
$rs->fields['relhasoids'] = $this->phpBool($rs->fields['relhasoids']);
return $rs->fields['relhasoids'];
} */
}
This column does not exist anymore, since you cannot create tables with OID any longer.
From the documentation:
WITH ( storage_parameter [= value] [, ... ] )
This clause specifies optional storage parameters for a table or index; see Storage Parameters for more information. For backward-compatibility the WITH clause for a table can also include OIDS=FALSE to specify that rows of the new table should not contain OIDs (object identifiers), OIDS=TRUE is not supported anymore.
WITHOUT OIDS
This is backward-compatible syntax for declaring a table WITHOUT OIDS, creating a table WITH OIDS is not supported anymore.
This is because phpPgAdmin is not compatible with PostgreSQL v. 12. PostgreSQL v. 12 has removed the relhasoids column because of the new way that OIDs are handled. As of the time of this post, pgPgAdmin does not support PostgreSQL v. 12 (it is not listed on the website). You may need to look into alternate clients.
See also How to fix “ERROR: column c.relhasoids does not exist” in Postgres?
I'm having trouble with the column name of one of my tables.
My version of DB2 is DB2/LINUXX8664 11.1.0. I'm running it on a CentOS Linux Release 7.2.1511. My version of IBM Data Studio is 4.1.2.
The column is named "NRO_AÑO" in the table "PERIODO" in the schema "COMPRAS".
When I execute the simple query
SELECT NRO_AÑO
FROM COMPRAS.PERIODO
it yields the following error:
"NRO_AÑO" is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=3.68.61
If I execute the query
SELECT *
FROM COMPRAS.PERIODO
it yields data with the following columns
I'm guessing it has something to do with the charsets involved, but I'm not sure where to look at.
Thanks in advance.
It worked for me:
[db2inst1#server ~]$ db2 "create table compras.periodo (nro_año int)"
DB20000I The SQL command completed successfully.
[db2inst1#server ~]$ db2 "insert into compras.periodo values (1)"
DB20000I The SQL command completed successfully.
[db2inst1#server ~]$ db2 "insert into compras.periodo (nro_año) values (2)"
DB20000I The SQL command completed successfully.
[db2inst1#server ~]$ db2 "select nro_año from compras.periodo"
NRO_AÑO
-----------
1
2
2 record(s) selected.
Probably, you are having a console encoding problem (putty), and you should review how the name of the column in the database is stored:
db2 "select colname from syscat.columns where tabname = 'PERIODO'"
COLNAME
--------------------------------------------------------------------------------------------------------------------------------
NRO_AÑO
1 record(s) selected.
Creating the table from Putty (SSH client) and then selecting from Data Studio, then the characters higher that 128 will have different representations. Java (DataStudio) uses UTF-8, but probably the script used to create the table used another encoding and this is having problems in the database (Putty, Windows, Notepad, etc).
It worked for me when I run the script from DB2 command line processor on DB2 9.7.
db2 => CREATE TABLE TEMP_TABLE(NRO_AÑO INTEGER)
DB20000I The SQL command completed successfully.
db2 => INSERT INTO TEMP_TABLE(NRO_AÑO) VALUES(1)
DB20000I The SQL command completed successfully.
db2 => SELECT * FROM TEMP_TABLE
NRO_AÑO
-----------
1
1 record(s) selected.
db2 => select colname from syscat.columns where tabname = 'TEMP_TABLE'
COLNAME
------------
NRO_AÑO
1 record(s) selected.
Your issue may also be that columns need to be enclosed in quotes, as found in IBM Data Studio Ver 4, example:
INSERT INTO DB2ADMIN.FB_WEB_POSTS ("UserName","FaceID", "FaceURL","FaceStory","FaceMessage","FaceDate","FaceStamp")
VALUES ('SocialMate','233555900032117_912837012103999', 'http://localhost/doculogs.nsf/index.html', 'Some Message or Story','Random Files Project for Lotus Notes, Google, Oracle App samples', '2017-09-09', '2017-09.23');
When I try to do
set schema foo
SELECT COMPANY_NO, COUNTRY_CODE FROM CRED_PROC_COMPANIES
And do session -> scripts -> store result of sql in file
it fails with
Error: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704,
Error: DB2 SQL Error: SQLCODE=-514, SQLSTATE=26501
What is the issue?
You need to set the schema inside the select statement like SELECT COMPANY_NO, COUNTRY_CODE FROM foo.CRED_PROC_COMPANIES