SQL Scalar table Data Types
//Data types within column definition
TEXT and CHAR(n), VARCHAR(n): text based types,
DATE, TIME, TIMESTAMP, and INTERVAL: include date and time types
JSON: for semi structured data,
INT, REAL: for numeric types and
ENUM, ARRAY: specialized types//CHAR and VARCHAR without (n) will be treated as CHAR(1) and TEXT respectively.
CREATE TABLE resorce (
primo CHAR(20), secondo VARCHAR(20), terzo TEXT
);
insert into resorce(primo, secondo, terzo)
values (' accidenti ', ' accidenti ', ' accidenti ');
//(" accidenti "," accidenti "," accidenti ")//We can concatenate different data types.
select (text 'prima ' || ' e ' || 211 ); //TEXT "prima e 211"
//We can concatenate string values from columns.
SELECT nome || ' ' || titolo as new_sting FROM parole;
//The strings follow the 1-index rule, like the arrays
select substring('parola'::text from 1 for 3); //par
SELECT substring(nome FROM 1 FOR 5) FROM parole; //It selects from table columns
//It can either be a specific column or a stirng value, it replaces the substring
select replace('mottura'::text, 'ttu', 'lla' ); //mollara
SELECT replace(nome, 'pre', 'post') FROM parole where id=2;JSON and REAL

ENUM and ARRAY
PreviousDatabase 1: SQL Databases with DBeaver, SQL Scripts, and the Node-Postgres ModuleNextRange, Multiranges and composite data types
Last updated