public inbox for [email protected]
help / color / mirror / Atom feedCURRENTE_DATE
5+ messages / 4 participants
[nested] [flat]
* CURRENTE_DATE
@ 2024-10-22 11:31 Rossana Ocampos <[email protected]>
0 siblings, 3 replies; 5+ messages in thread
From: Rossana Ocampos @ 2024-10-22 11:31 UTC (permalink / raw)
To: [email protected]
Hello ,
I am new with PostgreSQL and I have a bug. I have created a function that
has an input variable of type date , in case it does not receive value , it
has to assume by default the current date.
I have defined it as follows variable DATE DEFAULT CURRENT_DATE, but I get
the following error.
El error
ERROR: invalid input syntax for type date: "CURRENT_DATE" LINE 1:
...extsupplydate ('1085018'::bigint, '5278'::bigint, 'CURRENT_D... ^ ERROR:
invalid input syntax for type date: "CURRENT_DATE" SQL status: 22007
Characters: 78
Please could you help me, thank you very much.
Rossana
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: CURRENTE_DATE
@ 2024-10-23 12:49 Rich Shepard <[email protected]>
parent: Rossana Ocampos <[email protected]>
2 siblings, 0 replies; 5+ messages in thread
From: Rich Shepard @ 2024-10-23 12:49 UTC (permalink / raw)
To: [email protected]
On Tue, 22 Oct 2024, Rossana Ocampos wrote:
> I am new with PostgreSQL and I have a bug. I have created a function that
> has an input variable of type date , in case it does not receive value ,
> it has to assume by default the current date.
> ERROR: invalid input syntax for type date: "CURRENT_DATE" LINE 1:
> ...extsupplydate ('1085018'::bigint, '5278'::bigint, 'CURRENT_D... ^ ERROR:
> invalid input syntax for type date: "CURRENT_DATE" SQL status: 22007
> Characters: 78
Rossana,
I have several tables with default values, including dates. Change your
input's values to `default' (without the quotes.)
Regards,
Rich
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: CURRENTE_DATE
@ 2024-10-23 12:55 Rich Shepard <[email protected]>
parent: Rossana Ocampos <[email protected]>
2 siblings, 0 replies; 5+ messages in thread
From: Rich Shepard @ 2024-10-23 12:55 UTC (permalink / raw)
To: [email protected]
On Tue, 22 Oct 2024, Rossana Ocampos wrote:
> ERROR: invalid input syntax for type date: "CURRENT_DATE" LINE 1:
> ...extsupplydate ('1085018'::bigint, '5278'::bigint, 'CURRENT_D... ^ ERROR:
> invalid input syntax for type date: "CURRENT_DATE" SQL status: 22007
> Characters: 78
Rossana,
Also, I suggest you put the column names (not their data types) separate
from the values. Here's an example of a script I use (Slackware64 linux):
\d enforcement
Table "public.enforcement"
Column | Type | Collation | Nullable | Default
----------------+---------+-----------+----------+--------------
company_nbr | integer | | |
action_date | date | | not null | CURRENT_DATE
penalty_amount | real | | |
reason | text | | |
comment | text | | |
Foreign-key constraints:
"enforcement_company_nbr_fkey" FOREIGN KEY (company_nbr) REFERENCES companies(company_nbr) ON UPDATE CASCADE ON DELETE RESTRICT
insert into enforcement (company_nbr, action_date, penalty_amount, reason, comment) values (123, '2024-10-23', default, 'Did a wrong thing.', null);
HTH,
Rich
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: CURRENTE_DATE
@ 2024-10-23 13:18 Ray O'Donnell <[email protected]>
parent: Rossana Ocampos <[email protected]>
2 siblings, 1 reply; 5+ messages in thread
From: Ray O'Donnell @ 2024-10-23 13:18 UTC (permalink / raw)
To: Rossana Ocampos <[email protected]>; [email protected]
On 22/10/2024 12:31, Rossana Ocampos wrote:
>
> *Hello ,*
>
> I am new with PostgreSQL and I have a bug. I have created a function
> that has an input variable of type date , in case it does not receive
> value , it has to assume by default the current date.
>
> I have defined it as follows variable DATE DEFAULT CURRENT_DATE, but
> I get the following error.
>
> *_El error _*
>
> ERROR: invalid input syntax for type date: “CURRENT_DATE” LINE 1:
> ...extsupplydate ('1085018'::bigint, '5278'::bigint, 'CURRENT_D... ^
> ERROR: invalid input syntax for type date: “CURRENT_DATE” SQL status:
> 22007 Characters: 78
>
I think you just need to leave off the quotes, as current_date is a
function:
insert into .... values ( ... , current_date, ....);
Also, you don't need to quote the bigint values.
HTH,
Ray.
> Please could you help me, thank you very much.
>
> Rossana
>
--
Raymond O'Donnell // Galway // Ireland
[email protected]
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: CURRENTE_DATE
@ 2024-10-24 13:01 Muhammad Ikram <[email protected]>
parent: Ray O'Donnell <[email protected]>
0 siblings, 0 replies; 5+ messages in thread
From: Muhammad Ikram @ 2024-10-24 13:01 UTC (permalink / raw)
To: Ray O'Donnell <[email protected]>; +Cc: Rossana Ocampos <[email protected]>; [email protected]
Hi,
I am just thinking, when DEFAULT CURRENT_DATE is being used in table
definition then why the function is again being used in INSERT statement
why not use
default. Here is sample
edb=# create table date_test (id int, hiredate date default current_date);
CREATE TABLE
edb=# insert into date_test values (1, *default*);
INSERT 0 1
edb=# select * from date_test;
id | hiredate
----+--------------------
1 | 24-OCT-24 00:00:00
(1 row)
Regards,
Ikram
On Wed, Oct 23, 2024 at 6:18 PM Ray O'Donnell <[email protected]> wrote:
> On 22/10/2024 12:31, Rossana Ocampos wrote:
>
> *Hello ,*
>
> I am new with PostgreSQL and I have a bug. I have created a function that
> has an input variable of type date , in case it does not receive value , it
> has to assume by default the current date.
>
> I have defined it as follows variable DATE DEFAULT CURRENT_DATE, but I
> get the following error.
>
>
>
> *El error *
>
> ERROR: invalid input syntax for type date: “CURRENT_DATE” LINE 1:
> ...extsupplydate ('1085018'::bigint, '5278'::bigint, 'CURRENT_D... ^ ERROR:
> invalid input syntax for type date: “CURRENT_DATE” SQL status: 22007
> Characters: 78
>
>
> I think you just need to leave off the quotes, as current_date is a
> function:
>
> insert into .... values ( ... , current_date, ....);
>
> Also, you don't need to quote the bigint values.
>
>
> HTH,
>
> Ray.
>
>
>
>
> Please could you help me, thank you very much.
>
> Rossana
>
>
>
> --
> Raymond O'Donnell // Galway // [email protected]
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-10-24 13:01 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-10-22 11:31 CURRENTE_DATE Rossana Ocampos <[email protected]>
2024-10-23 12:49 ` Rich Shepard <[email protected]>
2024-10-23 12:55 ` Rich Shepard <[email protected]>
2024-10-23 13:18 ` Ray O'Donnell <[email protected]>
2024-10-24 13:01 ` Muhammad Ikram <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox