Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

generate-series

How to insert data in postgresql using for loop?

November 23, 2023 by Tarik

Please try below code to insert values in tables using for loop. do $$ begin for r in 1..1000 loop insert into schema_name.table_name(id) values(r); end loop; end; $$;

Categories sql Tags generate-series, postgresql, sql, sql-insert Leave a comment

How can I generate a series of repeating numbers in PostgreSQL?

September 16, 2023 by Tarik

You could cross join it to a series of 3: SELECT a.n from generate_series(1, 100) as a(n), generate_series(1, 3)

Categories sql Tags generate-series, postgresql, sql Leave a comment

How to perform a select query in a DO block?

August 15, 2023 by Tarik

DO command vs. PL/pgSQL function A DO command does not return rows. You can send NOTICES or RAISE other messages (using default LANGUAGE plpgsql), or you can write to a (temporary) table and later SELECT from it to get around this. But really, create a function instead, where you can define a return type with … Read more

Categories sql Tags generate-series, plpgsql, postgresql, postgresql-9.1, sql Leave a comment

Generating time series between two dates in PostgreSQL

December 9, 2022 by Tarik

Can be done without conversion to/from int (but to/from timestamp instead) SELECT date_trunc(‘day’, dd):: date FROM generate_series ( ‘2007-02-01’::timestamp , ‘2008-04-01’::timestamp , ‘1 day’::interval) dd ;

Categories sql Tags generate-series, postgresql, postgresql-9.1, sql, time-series Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa