add range of number (1..5) in one column in postgresql [closed]
I want to insert into a column a range of number 1 to 5
INSERT INTO public.npc(name, gold, info, id, quest_level)
VALUES ('test',200,'do_that',1,(1..5)
sql postgresql
closed as unclear what you're asking by Maurice Meyer, Cindy Meister, lagom, greg-449, arnt Nov 23 '18 at 10:40
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I want to insert into a column a range of number 1 to 5
INSERT INTO public.npc(name, gold, info, id, quest_level)
VALUES ('test',200,'do_that',1,(1..5)
sql postgresql
closed as unclear what you're asking by Maurice Meyer, Cindy Meister, lagom, greg-449, arnt Nov 23 '18 at 10:40
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22
add a comment |
I want to insert into a column a range of number 1 to 5
INSERT INTO public.npc(name, gold, info, id, quest_level)
VALUES ('test',200,'do_that',1,(1..5)
sql postgresql
I want to insert into a column a range of number 1 to 5
INSERT INTO public.npc(name, gold, info, id, quest_level)
VALUES ('test',200,'do_that',1,(1..5)
sql postgresql
sql postgresql
edited Nov 22 '18 at 21:21
a_horse_with_no_name
296k46451546
296k46451546
asked Nov 22 '18 at 20:47
local hostlocal host
52
52
closed as unclear what you're asking by Maurice Meyer, Cindy Meister, lagom, greg-449, arnt Nov 23 '18 at 10:40
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Maurice Meyer, Cindy Meister, lagom, greg-449, arnt Nov 23 '18 at 10:40
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22
add a comment |
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22
add a comment |
2 Answers
2
active
oldest
votes
I am assuming that your quest_level
has the data type int
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level int
);
In this case you could insert your values like this:
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i)
FROM generate_series(1,5) as g(i)));
In case quest_level
has another data type, e.g. text
then a cast is necessary:
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level text
);
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i) :: text
FROM generate_series(1,5) as g(i)));
add a comment |
If you want to introduce 5 rows, then:
INSERT INTO public.npc(name, gold, info, id, quest_level)
SELECT 'test', 200, 'do_that', 1, gs.n
FROM generate_series(1, 5) gs(n);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am assuming that your quest_level
has the data type int
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level int
);
In this case you could insert your values like this:
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i)
FROM generate_series(1,5) as g(i)));
In case quest_level
has another data type, e.g. text
then a cast is necessary:
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level text
);
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i) :: text
FROM generate_series(1,5) as g(i)));
add a comment |
I am assuming that your quest_level
has the data type int
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level int
);
In this case you could insert your values like this:
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i)
FROM generate_series(1,5) as g(i)));
In case quest_level
has another data type, e.g. text
then a cast is necessary:
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level text
);
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i) :: text
FROM generate_series(1,5) as g(i)));
add a comment |
I am assuming that your quest_level
has the data type int
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level int
);
In this case you could insert your values like this:
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i)
FROM generate_series(1,5) as g(i)));
In case quest_level
has another data type, e.g. text
then a cast is necessary:
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level text
);
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i) :: text
FROM generate_series(1,5) as g(i)));
I am assuming that your quest_level
has the data type int
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level int
);
In this case you could insert your values like this:
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i)
FROM generate_series(1,5) as g(i)));
In case quest_level
has another data type, e.g. text
then a cast is necessary:
CREATE TABLE public.npc(
name text,
gold int,
info text,
id int,
quest_level text
);
INSERT INTO public.npc (name, gold, info, id, quest_level) VALUES
('test',200,'do_that',1, (SELECT array_agg(g.i) :: text
FROM generate_series(1,5) as g(i)));
answered Nov 22 '18 at 21:10
TonyTony
398211
398211
add a comment |
add a comment |
If you want to introduce 5 rows, then:
INSERT INTO public.npc(name, gold, info, id, quest_level)
SELECT 'test', 200, 'do_that', 1, gs.n
FROM generate_series(1, 5) gs(n);
add a comment |
If you want to introduce 5 rows, then:
INSERT INTO public.npc(name, gold, info, id, quest_level)
SELECT 'test', 200, 'do_that', 1, gs.n
FROM generate_series(1, 5) gs(n);
add a comment |
If you want to introduce 5 rows, then:
INSERT INTO public.npc(name, gold, info, id, quest_level)
SELECT 'test', 200, 'do_that', 1, gs.n
FROM generate_series(1, 5) gs(n);
If you want to introduce 5 rows, then:
INSERT INTO public.npc(name, gold, info, id, quest_level)
SELECT 'test', 200, 'do_that', 1, gs.n
FROM generate_series(1, 5) gs(n);
answered Nov 23 '18 at 2:57
Gordon LinoffGordon Linoff
770k35303404
770k35303404
add a comment |
add a comment |
What data type is it supposed to be ?
– Tony
Nov 22 '18 at 20:52
Do you want to store all values in that range, or just the start and end of the range? If the latter, use a range type
– a_horse_with_no_name
Nov 22 '18 at 21:22