Bug 71224 - Insert new fields between existing fields not working (ALTER TABLE ADD BEFORE/AFTER)
Summary: Insert new fields between existing fields not working (ALTER TABLE ADD BEFORE...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: needsDevEval
: 105935 153340 (view as bug list)
Depends on:
Blocks: Database-Tables
  Show dependency treegraph
 
Reported: 2013-11-04 16:33 UTC by Wayne
Modified: 2023-02-03 07:58 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments
test database (2.39 KB, application/vnd.oasis.opendocument.database)
2014-07-17 10:28 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wayne 2013-11-04 16:33:08 UTC
The "Insert Rows" into a table doesn't do as it states. I want to insert new field names and spaces to group things together. Upon choosing the "Insert Rows" from the drop down menu the green pointing arrow goes to the bottom of the field names list to enter a new field there instead of where I wanted it to be entered.
Comment 1 Robert Großkopf 2013-11-04 17:02:20 UTC
You have opened a table for editing, right?
With the GUI you could only insert new rows at the end of the table. If you wish to position a new field in this table at another place, you have to do this by the possibilities of the database.
With the internal HSQLDB the following possibility is given:
ALTER TABLE "Tablename" ADD "Fieldname" VARCHAR(25) BEFORE "Existing Fieldname";
Open Tools → SQL and try this possibility.

The GUI could only offer, what the database allows. And there is no possibility in the database to resort existing fields.

What do you mean with "spaces" when creating a table?
Comment 2 Kevin Suo 2014-04-29 11:08:52 UTC
I can confirm this, this is a bug.

Steps to reproduce:
1. New table, define 3 fields, stay in table design view;
2. Right-click -> Insert Row between the 1st and 2nd field. (a new field is inserted as expected.)
3. Save the table;
4. Table design view, try to insert a field between the 1st and 2nd field.

Current behaviour:
Insert a field between two existing fields not possible.

Expected:
Users can insert new fields or sort existing fields (when the database allows).
As this can be done by sql command, this should also be done in GUI.
Comment 3 Robert Großkopf 2014-04-29 15:41:29 UTC
This never worked before. So I set the Version to "Inherited From OOo".

It was not implemented into the GUI for changing a table. There are very much SQL-statements, which doesn't work in the GUI, but would work with direct SQL (example: Default values in tabledesign and other default-values in  SQL). So this is a ask for an enhancement.
Comment 4 Kevin Suo 2014-07-17 10:10:20 UTC
I set this feature request to highest, because this is the main reason which blocks me from using libreoffice base.

To design a table, nobody can make all the fields done during the first time they create a table. They have to move/insert fields later if needed. Currently it's only possible to run SQL commands to re-arrange field order.

Almost all the database management software allows to insert fields between two fields which already exist, except libreoffice base.
Comment 5 Kevin Suo 2014-07-17 10:28:33 UTC
Created attachment 102977 [details]
test database

steps:
1. Try to insert a new field "CITY" before "NAME", AFTER "ID".

In the GUI, the inserted fields always go to the bottom.

From tools-sql, run:
ALTER TABLE "Table1" ADD "CITY" VARCHAR(25) BEFORE "NAME";

New field is correctly inserted.
Comment 6 Björn Michaelsen 2014-08-21 12:21:16 UTC Comment hidden (obsolete)
Comment 7 Alex Thurgood 2015-01-03 17:40:29 UTC Comment hidden (no-value)
Comment 8 Alex Thurgood 2016-09-16 09:31:36 UTC
It is not a bug, rather more a feature request, as the feature did not exist already when the LibreOffice project came into being. As Robert has correctly stated in comment 1, new fields are currently always added to the end of the table definition, so the UI does not currently cater for the possibility of adding new fields before/after other fields or changing the order of fields in a database table.

Should such a feature be enabled ? Yes, absolutely, as the UI seems, at least in appearance from the context menu, to allow this. Confirming that this indeed is a feature request. Whether or not this is high on the list of priorities for Base is another matter. The current feature deficit can be resolved by resorting to SQL commands via the Tools > SQL menu entry, so there is a workaround. Consequently, this RFE is probably not going to feature as a high priority, unless someone volunteers to do the coding.
Comment 9 Alex Thurgood 2016-09-16 09:37:09 UTC
The other alternative would be to remove the "Insert Rows" entry from the context menu, so that users would not be misled, leaving only the current UI direct mouse click addition of adding a new field to the end of the already available fields, however, it would be better to strive for a product that allows such changes as originally intended.
Comment 10 Lionel Elie Mamane 2016-09-16 15:38:33 UTC
Not all databases support adding new fields at an arbitrary place in the table. For example PostgreSQL does not, it can add only at the end.

Whether embedded HSQLDB (and embedded Firebird) supports it, I'm not sure out of the top of my head. If it does, yes, it would be nice for the GUI to support it.
Comment 11 Heiko Tietze 2016-12-29 09:00:46 UTC
Removing needsUXEval. Ideally "Insert Row" works as expected (and actually is effective when the new table hasn't been saved), as known from Kexi for instance (formerly part of the Calligra suite). Alternatively a simple renaming to "Add row" is also possible.
Comment 12 Robert Großkopf 2017-02-12 09:53:29 UTC
*** Bug 105935 has been marked as a duplicate of this bug. ***
Comment 13 Buovjaga 2017-02-12 16:34:16 UTC Comment hidden (obsolete)
Comment 14 Robert Großkopf 2017-02-12 16:59:35 UTC
HSQLDB supports adding a new field at a position before an old field.
ALTER TABLE "Table" ADD "Name" VARCHAR(25) BEFORE "Existing Fieldname";

Firebird supports this:
ALTER TABLE "Table" ADD "Name" VARCHAR(25);
ALTER TABLE "Table" ALTER "Name" POSITION 2;

With Firebird you have to insert the row first. Then you could change the position of the row afterwords. So it does work also with old and new added fields.

Would be good if GUI supports adding a *new* field at a special position, because both internal databases will support to set a field this way.
Comment 15 Stéphane Guillou (stragu) 2023-02-03 07:58:23 UTC
*** Bug 153340 has been marked as a duplicate of this bug. ***