Cant change table colum [closed] - db2

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Iam just trying to rename the column in my table.
Column name: AGGREGATE_ID
Data type name: CHARACTER
Length: 15
ALTER TABLE 'headers' CHANGE 'aggregate_id' 'ENGINE' char(15)
I always get the error masssage
"ALTER TABLE 'headers' CHANGE 'aggregate_id' 'ENGINE'char(15)
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "ALTER TABLE 'headers' CHANGE 'agg" was found
following "BEGIN-OF-STATEMENT". Expected tokens may include:
"<create_variable>". SQLSTATE=42601"
I dont know what to do anymore :(

In Db2, renaming a column as ALTER TABLE is done like this:
ALTER TABLE "headers" RENAME COLUMN "aggregate_id" TO ENGINE
If you use double quotes around an identifier, it is stored as provided. If you don't use the quotes, the string is converted to uppercase. Hence I did not use quotes for ENGINE.

Related

Can't add item in Postgres using pgAdmin [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 14 days ago.
Improve this question
I am trying to use Postgres with Django application.
I am using pgAdmin to manage Postgres database.
But I can't add new item to database using pgAdmin manually.
Once I typed data manually and clicked the save button, I got
ERROR: invalid input syntax for type uuid: "111"
LINE 3: '111'::uuid, 'asdfasdfdasf'::character varying)
^
Schema is just simple.
Just id and name in the table.
Please help me to fix the issue.
Thank you.
Try to add a default auto-generated value for your id field with the following commands:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
ALTER TABLE public.table_name
ALTER COLUMN "id" SET DEFAULT uuid_generate_v4();
After that, you need to populate only the name column.

How to change start value of sequence in Postgres [duplicate]

This question already has answers here:
How to reset Postgres' primary key sequence when it falls out of sync?
(33 answers)
Closed 4 months ago.
I have a table which was populated with data from another environment. When I try to create a new entry it tells me:
ERROR: duplicate key value violates unique constraint "chart_of_account_dimension_config_pkey"
Detail: Key (id)=(1) already exists.
I tried resetting the starting value of the sequence to an higher value by:
select setval(chart_of_account_dimension_id_seq1, 2810, true)
But it tells me
column "chart_of_account_dimension_config_id_seq1" does not exist
I tried to run following query, and actually there is no such sequence.
But dBeaver tells me such a sequence exists.
Edit: Why postgres thinks that chart_of_account_dimension_config_id_seq1 is a column name whereas in reality it is a sequence name.
If the query parser sees an identifier like that in that place it tries to treat it as a column.
So you need to do:
select setval('chart_of_account_dimension_id_seq1'::regclass, 2810, true)
That will look up the text name of the sequence and give its underlying identifier.
If you check the output of \dt you should see a similar thing with the DEFAULT for the column using it.

is primary key automatically indexed in postgresql? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have created table name as d with ID column as primary key and then just inserted records as shown in output, but after fetching all records this output still displayed same as order in which records are inserted. but output as a see now not in ordered form.
PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness. Thus, it is not necessary to create an index explicitly for primary key columns. (See CREATE INDEX for more information.)
Source:
Docs
but after fetching all records this output still displayed same as order in which records are inserted
There is NO default "sort" order - even if there is an index on that column (which indeed is the case in Postgres: the primary key is supported by a unique index in the background)
Rows in a relational table are not sorted.
The only (really: the only) way to get a specific order is to use an ORDER BY
If you do not specify an ORDER BY the database is free to return the rows in any order it wants - and that order can change at any time.
The order can change because of various reasons:
other sessions are running the same statement
the table was updated
the execution plan changes
...
In addition to what the others have said, Postgres does not have a concept of a 'Clustered Index' like Microsoft SQL Server and other databases have. You can cluster an index, but it is a one-time operation (until you call it again) and will not maintain the clustering of rows upon edits, etc. See the docs
I was running into the same thing you were, where I half expected the rows to be returned in order of primary key (I didn't insert them out of order like you did, though). They did come back upon initial insert, but editing a record in Postgres seems to move the record to the end of the page, and the records quickly became out of order (I updated fields other than the primary key).

Need help to solve db2 sqlcode=-204 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I create tables with data studio but when I try to access that table from java application, or db2 command console, I get -204 which means the object that I am trying to access is not defined. But in fact it is defined, because I am able to list the tables in db2 command console, but I am not able to select or insert into that table. Please help me if possible. I've already spent 1.5 day on this.
Let's suppose you are using the johndoe user.
How are you creating the tables?
create table myTable (col1 int)
Or like this
create table myschema.myTable (col1 int)
The first table will be created in the catalog as follow:
johndoe.myTable
The second one as
myschema.myTable
As you can see, if no schema is specified, the username will be used as schema.
You can check the tables currently created in db2 with this query
select varchar(tabschema,20), varchar(tabname, 20)
from syscat.tables
where tabschema not like 'SYS%'
In this way you will know what exist in the database.

How could update the old row's value when I alter table add column and set default value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How could update the old row's value when I alter table add column default value
type smallint NOT NULL DEFAULT 0
but old rows is still null, Why can't update to default value automatic?
Issue an update statement prior to the alter table statement in your transaction:
update table set col = 0 where col is null
Alter table won't update the data because it's not its job or responsibility; updating is update's job. (The only exception I'm aware is when you change a column's type, in which case you can toss in a using clause to transform the data as you need.)