[Solved] Setting CURRENT DATE for type DATE

Creating tables and queries
Post Reply
User avatar
DynV
Posts: 196
Joined: Tue Apr 06, 2010 10:50 pm
Location: Montreal, Canada

[Solved] Setting CURRENT DATE for type DATE

Post by DynV »

I'm trying to set a DATE field default to the current one. The solution that seemed the best was Default to Todays Date (View topic) • Apache OpenOffice Community Forum [by DrewJensen » Tue Nov 27, 2007 6:54 pm]; I executed

Code: Select all

ALTER TABLE "snapshots" ALTER COLUMN "date" DEFAULT CURRENT_DATE
(in menu > Tools > SQL...) resulting the status
1: Wrong data type: DEFAULT in statement [ALTER TABLE "snapshots" ALTER COLUMN "date" DEFAULT]
Am I doing something wrong? Is this the good path for my goal?

If necessary, here's the scheme:

Code: Select all

SET DATABASE COLLATION "Latin1_General"
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE CACHED TABLE "snapshots"("ID" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,"date" DATE,"date_id" TINYINT,"bg_bar_len" SMALLINT NOT NULL)
CREATE UNIQUE INDEX "date_date_id" ON "snapshots"("date","date_id")
CREATE CACHED TABLE "traits"("ID" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,"name" VARCHAR_IGNORECASE(50) NOT NULL)
CREATE CACHED TABLE "snapshots_traits"("snapshot_id" INTEGER NOT NULL,"trait_id" INTEGER NOT NULL,"value" SMALLINT NOT NULL,PRIMARY KEY("snapshot_id","trait_id"),CONSTRAINT SYS_FK_70 FOREIGN KEY("trait_id") REFERENCES "traits"("ID") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT SYS_FK_73 FOREIGN KEY("snapshot_id") REFERENCES "snapshots"("ID") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE CACHED TABLE "tables_fields_description"("table_name" VARCHAR_IGNORECASE(50) NOT NULL,"field_name" VARCHAR_IGNORECASE(50) NOT NULL,"description" VARCHAR(1024) NOT NULL,PRIMARY KEY("table_name","field_name"))
ALTER TABLE "snapshots" ALTER COLUMN "ID" RESTART WITH 0
ALTER TABLE "traits" ALTER COLUMN "ID" RESTART WITH 0
Thank you kindly
Last edited by DynV on Wed Jan 11, 2017 3:01 am, edited 1 time in total.
Je suis francophone.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting CURRENT DATE for type DATE doesn't seem to work

Post by Villeroy »

Either you specify all column properties ... "date" AS DATE DEFAULT CURRENT_DATE NOT NULL
Or you change the default value with the SET keyword ... "date"

Code: Select all

SET
DEFAULT CURRENT_DATE

http://www.hsqldb.org/doc/1.8/guide/ch0 ... le-section
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
DynV
Posts: 196
Joined: Tue Apr 06, 2010 10:50 pm
Location: Montreal, Canada

Re: Setting CURRENT DATE for type DATE doesn't seem to work

Post by DynV »

executed

Code: Select all

ALTER TABLE "snapshots" ALTER COLUMN "date" SET DEFAULT CURRENT_DATE
status
1: Command successfully executed.
thanks again
Je suis francophone.
Post Reply