add range of number (1..5) in one column in postgresql [closed]












0















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)









share|improve this 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
















0















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)









share|improve this 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














0












0








0








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)









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















0














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)));





share|improve this answer































    0














    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);





    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      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)));





      share|improve this answer




























        0














        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)));





        share|improve this answer


























          0












          0








          0







          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)));





          share|improve this answer













          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)));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 21:10









          TonyTony

          398211




          398211

























              0














              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);





              share|improve this answer




























                0














                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);





                share|improve this answer


























                  0












                  0








                  0







                  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);





                  share|improve this answer













                  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);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 2:57









                  Gordon LinoffGordon Linoff

                  770k35303404




                  770k35303404















                      Popular posts from this blog

                      To store a contact into the json file from server.js file using a class in NodeJS

                      Redirect URL with Chrome Remote Debugging Android Devices

                      Dieringhausen