SQL execution failed: operator does not exist: bigint >= timestamp without time zone - sql

CREATE TABLE employee (
id INT PRIMARY KEY,
username TEXT NOT NULL,
email TEXT NULL,
created_on TIMESTAMP NOT NULL,
);
SELECT username, email FROM employee where created_on between '2012-01-20' and '2012-04-24'

That actually seems to work: http://sqlfiddle.com/#!17/ef8e85/1
Mind though that you have a syntax error in your CREATE TABLE, you need to remove the last comma.

Related

Using like for numeric in a constraint

I am creating a table which is like this:
CREATE TABLE Peeps
(
Name VARCHAR(255) NOT NULL,
PhoneNum BIGINT NOT NULL,
CONSTRAINT PhoneNum_Check CHECK (PhoneNum LIKE '08%')
)
Every phone number has to start with 08. However when I tried insert there's an error because LIKE can't be used for numeric (or that's what my friend said). The alternative would be using VARCHAR for PhoneNum, but this is an assignment and we have to use numeric for the phone number.
If a phone number can start with a 0 then you need to use a string:
CREATE TABLE Peeps (
Name VARCHAR(255) NOT NULL,
PhoneNum VARCHAR(255) NOT NULL,
CONSTRAINT PhoneNum_Check CHECK (PhoneNum LIKE '08%')
);
Although you can use LIKE on a number, it is highly not recommended. What happens is that the number is converted to a string. However, that string will never start with a 0 -- well, at least never when the value is greater than 1.

I just want to use time in this colum (novice)

CREATE TABLE Vitals
(
Record_No int NOT NULL PRIMARY KEY,
Patient_ID int,
Date_Taken DATE NOT NULL,
Time_Taken time(7) NOT NULL,
Systolic int,
CHECK (Systolic > Diastolic),
Diastolic int,
Heart_Rate int CHECK (Heart_Rate > 30),
CONSTRAINT fk_Patient_ID FOREIGN KEY (Patient_ID) REFERENCES Patients(Patient_ID)
);
But, I get an error
Time_Taken time(7) NOT NULL,
*
ERROR at line 6:
ORA-00907: missing right parenthesis
When I use timestamp default systimestamp
it works. All I need is the time for Time_Taken column.
enter image description here
You can not use the TIME data type as it is not the oracle defined datatype.
You can use the DATE or TIMESTAMP data type to store time with date.
Supported data types in oracle are documented here.

Insert timestamp into PostgreSQL table

I would like to insert TIMESTAMP into column LAST_LOGIN
CREATE TABLE USER(
ID INTEGER NOT NULL,
USER_NAME TEXT,
FIRST_NAME TEXT,
LAST_NAME TEXT,
LAST_LOGIN DATE,
DATE_REGISTERED DATE,
ROLE INTEGER,
CAN_LOGIN INTEGER
)
;
ALTER TABLE USER ADD CONSTRAINT KEY1 PRIMARY KEY (ID)
;
I tried this:
UPDATE USERS SET LAST_LOGIN = TIMESTAMP WHERE USER_NAME = ?
But I get org.postgresql.util.PSQLException: ERROR: column "timestamp" does not exist Position: 31
What is the correct way to insert current time into table column LAST_LOGIN?
TIMESTAMP is not a known function is POSTGRES , therefore, it recognize it as a column .
POSTGRES dates/time functions:
NOW();
current_date;
current_time;
current_timestamp;
So your correct query should be
UPDATE USERS SET LAST_LOGIN = now() WHERE USER_NAME = ?
You can read all about postgres time/date functions in this document.
Maybe the error comes from using the wrong function. Try this instead:
UPDATE USERS SET LAST_LOGIN = CURRENT_TIMESTAMP WHERE USER_NAME = ?

Literal does not match format string when creating a table

I keep trying to create a basic table. Every time I try to create the table I get the error
literal does not match format string
I'm trying to limit the years of the tournament between 2005 and 2100. The error is between DATE '2005'.
This is my code:
Create table Tournament_T
(Tournament_name VARCHAR (50) PRIMARY KEY NOT NULL,
Tournament_year INTEGER NOT NULL,
CONSTRAINT RANGE CHECK (Tournament_year BETWEEN DATE '2005' AND '2100'),
Tournament_rules CLOB NOT NULL,
Tournament_fee VARCHAR(1000) NOT NULL,
Tournment_eligibility VARCHAR (1000) NOT NULL );
COMMIT;
Your constraint is using the date keyword, but you don't need it. Just do:
CONSTRAINT RANGE CHECK (Tournament_year BETWEEN 2005 AND 2100),
Your column is an integer, not a date.

ORA-001722 Invalid Number when insert in Oracle SQL

CREATE TABLE the_user( Name VARCHAR(40) not null,
Address VARCHAR(255) not null,
Delivery_address VARCHAR(255),
Email VARCHAR(25) not null,
Phone INTEGER not null,
Status INTEGER not null,
Password VARCHAR(25) not null,
DOB DATE not null,
PRIMARY KEY (Email),
FOREIGN KEY (Status) REFERENCES User_Status (Status_Id),
CONSTRAINT check_Password CHECK (Password > 4)
);
INSERT INTO the_user VALUES (
'Pergrin Took',
'12 Bag end, hobbiton, The Shire, Eriador',
'The address, Dublin',
'ptook#lotr.com',
'8679046',
'001',
'treebeard',
TO_DATE('2013/11/04 14:11:34', 'yyyy/mm/dd hh24:mi:ss')
);
I have the above database in Oracle but when I try to run the insert command I get an ORA-1722 error, Invalid Number. There is a entry in the user_status table which corresponds to the 1 in the insert.
I have been stuck on this for days.
Quotes are not a problem - it will be converted implicitly to numbers as far as they are valid.
Check your constraints:
CONSTRAINT check_Password CHECK (Password > 4)
Here you try to compare string and number -> in this comparison Oracle always tries to cast both as numbers -> password fails and you see an error.
Try to use instead of password e.g. '55' and you will see the row is inserted.
Perhaps you wanted to do this?
CONSTRAINT check_Password CHECK (length(Password) > 4)