Questions tagged [default-value]
For questions relating to DBMS-supplied values that are generated when none are explicitly provided.
10
questions
17
votes
2
answers
19k
views
Is there a way to insert multiple rows into a table with default values for all columns?
I can insert multiple rows into a table with default values for all columns the RBAR way:
create table course(course_id serial primary key);
do $$
begin
for i in 1..100000 loop
insert into ...
15
votes
3
answers
25k
views
Duplicate row with Primary Key in PostgreSQL
Assume I have a table as follows named people, where id is a Primary Key:
+-----------+---------+---------+
| id | fname | lname |
| (integer) | (text) | (text) |
+===========+=========+=...
2
votes
3
answers
5k
views
PostgreSQL execute a default query when no row are returned
I need to calculate the average score of a list of userId.
I have a table user_place_score:
(user_id, place_id, score)
Sometimes I do not have the score (no row for (user_id,place_id) in the table) ...
131
votes
3
answers
227k
views
Default value for UUID column in Postgres
In Postgres 9.x, for a column of type UUID, how do I specify a UUID to be generated automatically as a default value for any row insert?
6
votes
1
answer
4k
views
Why mysql throws "invalid default value for field" only when two or more timestamp fields exist in the create statement?
In mysql 5.7.28 I create a table like this:
create table t1 (
id int not null,
d1 timestamp)
engine=innodb;
which works fine and creates d1 as non-null with default value current_timetamp,on update ...
5
votes
1
answer
4k
views
How to set column DEFAULT using value of a variable
In a script for setting up a database which uses random UUIDs for primary keys, I have:
CREATE TABLE alpha (id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), value INT);
CREATE TABLE beta (aref UUID ...
3
votes
2
answers
4k
views
Inserting dummy data into an empty table having a primary key integer field GENERATED ALWAYS AS IDENTITY
I'm trying to generate dummy tables with dummy data for testing performance with some SQL tasks.
Based on this old thread: Is there a way to insert multiple rows into a table with default values for ...
3
votes
1
answer
2k
views
How can I get MySQL to use the value returned by a function as a default?
I have a pre-existing table that has a column to that can hold a UUID.
I'd like to be able to define a default such that new rows coming in (from legacy systems) will still get a UUID defined, via ...
1
vote
1
answer
1k
views
How do I an add a DEFAULT on a column if the table already exists?
I want to add a DEFAULT for a timestamp column in PostgreSQL. With SQL Server you use ALTER TABLE ADD CONSTRAINT
You can see the example in their docs,
ALTER TABLE dbo.doc_exz
ADD CONSTRAINT ...
0
votes
1
answer
314
views
What is the default column name given to a TABLE() type with a single column
CREATE OR REPLACE TYPE MISSING_KEYS AS TABLE OF VARCHAR2(256);
SELECT [¿what goes here?] as missing_key
FROM TABLE (MISSING_KEYS('A','B','C','D'))
What is the default column name that should be in [¿...