Yes, you can save a list in PostgreSQL by creating an array data type. Here's an example of how to create a table with an array column:

CREATE TABLE my_table (
  id SERIAL PRIMARY KEY,
  my_list INTEGER[]
);

This creates a table with two columns - an 'id' column that serves as the primary key and an array column called 'my_list' that can store a list of integers.

You can then insert data into this table with the following SQL statement:

INSERT INTO my_table (my_list) VALUES (ARRAY[1, 2, 3]);

This inserts a row with an array of integers [1, 2, 3] into the 'my_list' column. You can also update the array with the 'ARRAY_APPEND' function:

UPDATE my_table SET my_list = ARRAY_APPEND(my_list, 4) WHERE id = 1;

This adds the integer 4 to the end of the array in the row with 'id' 1.

Overall, PostgreSQL provides robust support for arrays and other complex data types, making it a powerful choice for storing and querying structured data.

How to Store Lists in PostgreSQL using Arrays

原文地址: https://www.cveoy.top/t/topic/ml9N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录