Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Sat, 12 Jan 2019, David G. Johnston wrote: Inserting new data into a table qualifies as "data change" in my mind... David, Then it's certainly good enough for me. ;-) Looking at the text file which the application will replace there are occasions when there's more than one contact on

Re: insert into: NULL in date column

2019-01-12 Thread David G. Johnston
On Sat, Jan 12, 2019 at 9:54 AM Rich Shepard wrote: > > The problem is that check constraints are only applied at time of data > > change. >I thought that the check constraint applied at data entry, too. Inserting new data into a table qualifies as "data change" in my mind... David J.

Re: insert into: NULL in date column

2019-01-12 Thread David G. Johnston
On Sat, Jan 12, 2019 at 10:08 AM Ricardo Martin Gomez wrote: > > Hi, > In MYSQL Null date is equal '01/01/1900' or '01/01/1970', I don't remember > but you can also use the same logic for the check_constraint. > Regards Why? PostgreSQL doesn't need hacks around this... David J.

Re: insert into: NULL in date column

2019-01-12 Thread Ricardo Martin Gomez
urday, January 12, 2019 1:54:47 PM To: pgsql-general@lists.postgresql.org Subject: Re: insert into: NULL in date column On Sat, 12 Jan 2019, David G. Johnston wrote: > NULL isn't the problem - a check constraint can resolve to unknown in > which case it behaves the same as if it resolve

Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Sat, 12 Jan 2019, David G. Johnston wrote: NULL isn't the problem - a check constraint can resolve to unknown in which case it behaves the same as if it resolved as true (i.e., its basically a IS NOT FALSE test in the backend). This is actually a nice feature of check constraints since for n

Re: insert into: NULL in date column

2019-01-12 Thread David G. Johnston
On Sat, Jan 12, 2019 at 9:01 AM Rich Shepard wrote: > > On Sat, 12 Jan 2019, David G. Johnston wrote: > > > Actually, you didn't ask about the check constraint, which is actually > > horribly broken since current_date is not an immutable function. >> >I know that nulls cannot be validly used i

Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Sat, 12 Jan 2019, David G. Johnston wrote: Actually, you didn't ask about the check constraint, which is actually horribly broken since current_date is not an immutable function. David, I know that nulls cannot be validly used in comparisons which makes the check constraint FUBAR. Thank

Re: insert into: NULL in date column

2019-01-12 Thread David G. Johnston
On Sat, Jan 12, 2019 at 6:43 AM Rich Shepard wrote: > > On Sat, 12 Jan 2019, Ricardo Martin Gomez wrote: > > > Hi, one question. > > Do you put explicit "NULL" in the column value? > > Other option is. > > You have to delete the column "next_contact" in your INSERT clause. > > So, if the column ha

Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Sat, 12 Jan 2019, Ricardo Martin Gomez wrote: Hi, one question. Do you put explicit "NULL" in the column value? Other option is. You have to delete the column "next_contact" in your INSERT clause. So, if the column has a default value, this value Will be inserted. Else Null value will be inse

Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Fri, 11 Jan 2019, David G. Johnston wrote: The default does seem a bit arbitrary and pointless... David, That answers my question about it. Thanks again. Best regards, Rich

Re: insert into: NULL in date column

2019-01-12 Thread Rich Shepard
On Fri, 11 Jan 2019, David G. Johnston wrote: VALUES (1, null, 3) is valid, VALUES (1,,3) is not. David, Using null occurred to me when I saw that an empty space still failed. Thanks for clarifying and confirming. Best regards, Rich

Re: insert into: NULL in date column

2019-01-11 Thread Ricardo Martin Gomez
k para Android<https://aka.ms/ghei36> De: Adrian Klaver Enviado: viernes, 11 de enero 22:09 Asunto: Re: insert into: NULL in date column Para: Rich Shepard, pgsql-general@lists.postgresql.org On 1/11/19 4:00 PM, Rich Shepard wrote: > On Fri, 11 Jan 2019, Ken Tanzer wrote: > >>

Re: insert into: NULL in date column

2019-01-11 Thread Adrian Klaver
On 1/11/19 4:00 PM, Rich Shepard wrote: On Fri, 11 Jan 2019, Ken Tanzer wrote: I think the problem is actually that you're trying to represent your NULL dates with '', which PG doesn't like. Ken,   That's certainly how I saw the error message. cat test.csv my_text,my_date,my_int 'Some Te

Re: insert into: NULL in date column

2019-01-11 Thread David G. Johnston
On Fri, Jan 11, 2019 at 4:25 PM Rob Sargent wrote: > We don't have more context in "activities.sql" but if your OP was > verbatim, it's keeling over on the comma ending the long text string. > Something syntactically askew I think. If the problem was where you described the parser would never hav

Re: insert into: NULL in date column

2019-01-11 Thread David G. Johnston
On Fri, Jan 11, 2019 at 3:56 PM Rich Shepard wrote: > > A table has this column definition: > > next_contact date DEFAULT '2020-11-06' > CONSTRAINT valid_next_date > CHECK (next_contact >= CURRENT_DATE), > > (and I don't know that it needs a default). The default d

Re: insert into: NULL in date column

2019-01-11 Thread David G. Johnston
On Fri, Jan 11, 2019 at 5:01 PM Rich Shepard wrote: > On Fri, 11 Jan 2019, Ken Tanzer wrote: > > \copy my_test FROM test.csv WITH CSV HEADER > > > > ERROR: invalid input syntax for type date: "''" > > CONTEXT: COPY my_test, line 4, column my_date: "''" Right problem wrong solution since it appe

Re: insert into: NULL in date column

2019-01-11 Thread Rich Shepard
On Fri, 11 Jan 2019, Ken Tanzer wrote: I think the problem is actually that you're trying to represent your NULL dates with '', which PG doesn't like. Ken, That's certainly how I saw the error message. cat test.csv my_text,my_date,my_int 'Some Text','1/1/18',3 'More Text,,2 'Enough','',1

Re: insert into: NULL in date column

2019-01-11 Thread Rich Shepard
On Fri, 11 Jan 2019, Rob Sargent wrote: Something syntactically askew I think. Rob, I agree that's the problem. Why there's a problem is what I need to learn. Thanks, Rich

Re: insert into: NULL in date column

2019-01-11 Thread Ken Tanzer
On Fri, Jan 11, 2019 at 3:25 PM Rob Sargent wrote: > > On 1/11/19 4:21 PM, Rich Shepard wrote: > > On Fri, 11 Jan 2019, Rob Sargent wrote: > > > >>> psql:activities.sql:2: ERROR: invalid input syntax for type date: "" > >>> LINE 2: ...reaction they''ve experienced environmental issues.','','');

Re: insert into: NULL in date column

2019-01-11 Thread Rob Sargent
On 1/11/19 4:21 PM, Rich Shepard wrote: On Fri, 11 Jan 2019, Rob Sargent wrote: psql:activities.sql:2: ERROR:  invalid input syntax for type date: "" LINE 2: ...reaction they''ve experienced environmental issues.','',''); ^ Mi

Re: insert into: NULL in date column

2019-01-11 Thread Rich Shepard
On Fri, 11 Jan 2019, Rob Sargent wrote: psql:activities.sql:2: ERROR:  invalid input syntax for type date: "" LINE 2: ...reaction they''ve experienced environmental issues.','','');     ^ Miss-matched single quotes in activities.sql?

Re: insert into: NULL in date column

2019-01-11 Thread Rob Sargent
On 1/11/19 3:56 PM, Rich Shepard wrote: A table has this column definition: next_contact date DEFAULT '2020-11-06'    CONSTRAINT valid_next_date    CHECK (next_contact >= CURRENT_DATE), (and I don't know that it needs a default). In an input statement that column is l